Node Rest and Http Clients with typings for use with TypeScript
Перейти к файлу
microsoft-github-policy-service[bot] c3af1e88c7
Updated for https://dev.azure.com/mseng/c86767d8-af79-4303-a7e6-21da0ba435e2/_build?definitionId=17099 by using baselines generated in https://dev.azure.com/mseng/c86767d8-af79-4303-a7e6-21da0ba435e2/_build/results?buildId=29045759
2024-09-09 10:19:18 +00:00
.config/1espt Updated for https://dev.azure.com/mseng/c86767d8-af79-4303-a7e6-21da0ba435e2/_build?definitionId=17099 by using baselines generated in https://dev.azure.com/mseng/c86767d8-af79-4303-a7e6-21da0ba435e2/_build/results?buildId=29045759 2024-09-09 10:19:18 +00:00
.github Update github workflows to avoid issues with GITHUB_TOKEN (#366) 2024-01-26 11:56:55 +01:00
ci Add release notes automatization (#365) 2023-11-30 12:05:55 +01:00
docs Update README, including adding debug steps (#130) 2019-02-26 13:43:55 -05:00
lib add EHOSTUNREACH to NetworkRetryErrors (#373) 2024-07-08 09:51:55 +02:00
samples Migration to CFS (#377) 2024-09-09 11:56:35 +02:00
test Migration to CFS (#377) 2024-09-09 11:56:35 +02:00
.gitignore Fix CG for typed-rest-client (#370) 2024-06-04 11:12:34 +02:00
.npmrc Migration to CFS (#377) 2024-09-09 11:56:35 +02:00
CONTRIBUTING.md Removed mention of node 4 support (#335) 2022-07-20 10:45:15 +04:00
LICENSE Write nock tests for all handlers and change codebase for NTLM handler (#194) 2020-01-10 11:29:35 -05:00
README.md Fix CG for typed-rest-client (#370) 2024-06-04 11:12:34 +02:00
SECURITY.md Microsoft mandatory file (#329) 2022-05-26 11:14:45 +02:00
ThirdPartyNotice.txt Add ThirdPartyNotice and copy that and package lock to _build. (#64) 2018-03-23 13:58:56 -04:00
azure-pipelines.yml Migration to CFS (#377) 2024-09-09 11:56:35 +02:00
generate-third-party-notice.js Add ThirdPartyNotice and copy that and package lock to _build. (#64) 2018-03-23 13:58:56 -04:00
issue_template.md Users/stfrance/issue template (#37) 2017-12-07 08:21:34 -05:00
make.js Update azure devops pipeline and fix tests (#357) 2023-06-27 14:11:28 +03:00
package-lock.json Migration to CFS (#377) 2024-09-09 11:56:35 +02:00
package.json add EHOSTUNREACH to NetworkRetryErrors (#373) 2024-07-08 09:51:55 +02:00
tsconfig.json refactor(casing): Force consistent casing (#25) 2017-11-30 17:55:52 -05:00

README.md

Build Status

Typed REST and HTTP Client with TypeScript Typings

A lightweight REST and HTTP client optimized for use with TypeScript with generics and async await.

Features

  • REST and HTTP client with TypeScript generics and async/await/Promises
  • Typings included so no need to acquire separately (great for intellisense and no versioning drift)
  • Basic, Bearer and NTLM Support out of the box. Extensible handlers for others.
  • Proxy support
  • Certificate support (Self-signed server and client cert)
  • Redirects supported

Intellisense and compile support:

intellisense

Install

npm install typed-rest-client --save

Or to install the latest preview:

npm install typed-rest-client@preview --save

Samples

See the samples for complete coding examples. Also see the REST and HTTP tests for detailed examples.

Errors

HTTP

The HTTP client does not throw unless truly exceptional.

  • A request that successfully executes resulting in a 404, 500 etc... will return a response object with a status code and a body.
  • Redirects (3xx) will be followed by default.

See HTTP tests for detailed examples.

REST

The REST client is a high-level client which uses the HTTP client. Its responsibility is to turn a body into a typed resource object.

  • A 200 will be success.
  • Redirects (3xx) will be followed.
  • A 404 will not throw but the result object will be null and the result statusCode will be set.
  • Other 4xx and 5xx errors will throw. The status code will be attached to the error object. If a RESTful error object is returned ({ message: xxx}), then the error message will be that. Otherwise, it will be a generic, Failed Request: (xxx).

See REST tests for detailed examples.

Debugging

To enable detailed console logging of all HTTP requests and responses, set the NODE_DEBUG environment varible:

export NODE_DEBUG=http

or

set NODE_DEBUG=http

Node support

v2 - [current, maintained] - Supports node 16 and above v1 - End Of Life, for Node < 16, contains security vulnerabilities, use at your own risk

Contributing

To contribute to this repository, see the contribution guide

To build:

$ npm run build

To run all tests:

$ npm test

To just run unit tests:

$ npm run units

Code of Conduct

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

Security Issues

Do you think there might be a security issue? Have you been phished or identified a security vulnerability? Please don't report it here - let us know by sending an email to secure@microsoft.com.