2.1.0 • Published 9 months ago

typed-rest-client v2.1.0

Weekly downloads
187,844
License
MIT
Repository
github
Last release
9 months ago

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.

holiday-checkerholiday-checker-testhomebridge-unifi-kids-crydhagberg-salesforce-sdknode-red-contrib-imsense-iot-platform@everything-registry/sub-chunk-2994taon-vscewindsdksupportwdio5-mocha-testrail-reporterweb3pay-sdk-jswechaty-plugin-intercomwechaty-intercomwendu-worker-testxiometfsrestservicevsts-task-tool-libvso-node-apivsce-yarn-patchvsce2vsce3value-auth-jsvscevsce-cjs@dogu-tech/node@collabee-tech/collabee-ch-audit@collabee-tech/collabee-ch-security@bytemain/vsce@petbee/cielo-clientjeeves-cliitem-level-downloaderjama-reporterketoolstrykertyped-azure-clienttyped-azure-kudutldrawlignin@akki9194/arm-rest-test-akshay@allseated-registry/mailinator-client@azure-actions/utilities@axosoft/azure-devops-node-api@alveo-vl/tsalveo@blackstarzes/homebridge-sonoff-basicr3@citrineos/ocpi-server@actionsflow/trigger-activitypubwasm-ociwebhookrelay-ws-clientvalist@honeysucklehealth/tsalesforce@heroku/salesforce-sdk@fluffy-spoon/action@inclusivelint/inclusivelint@infinitebrahmanuniverse/nolb-typed@itunes-scraper-sdk/podcast-tools@mpathirage/homebridge-gosundsw2-esphome@navadt/common@entan.gl/vsce@mitter-io/core@modelnest/cli@kimonocloud/cli@kimonocloud/kimono-core@juparog/df-plugin-adoption@purelightpower/podio-ts@salesforce/salesforce-sdk@starkmsu/azure-devops-node-api@o.calvo/register-service@slashauth/node-client@spirale-tech/copycat-sdk@socialsflow/trigger-activitypub@rentready/azure-devops-node-api@sdh100shaun/iptrackerms-choicesmite-api-tsmz-v3npm-registry-apiscraperlibscoresaber-api-clientserver-configuration-api-clientsetup-nuget-exenode-awnode-arlonode-red-contrib-imsense-iot-platform-x-1node-tp-link-powerlineplanethoster-apipicpay-sdkpipedrive-clientpipelines-appservice-libpipelines-appservice-lib-testrest-skidata-tdiproxyprobesocketxp-ws-clientsilverstripe-cms-dashboardiizunahyper-sdk-jsinclusivelintinclusivelint-libgui-wp-typescripthomebridge-mihomegatewayhomebridge-bloomskyhomebridge-xiaoaihomebridge-tabby-ts
2.1.0

9 months ago

2.0.2

11 months ago

2.0.1

12 months ago

2.0.0

1 year ago

1.8.10

2 years ago

1.8.11

2 years ago

1.8.9

3 years ago

1.8.6

4 years ago

1.8.5

4 years ago

1.8.4

4 years ago

1.8.3

4 years ago

1.8.1

4 years ago

1.8.0

5 years ago

1.7.3

5 years ago

1.7.2

5 years ago

1.7.1

5 years ago

1.7.0

5 years ago

1.5.0

6 years ago

1.4.0

6 years ago

1.2.0

6 years ago

1.1.2

6 years ago

1.0.11

7 years ago

1.0.9

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago

0.15.1

8 years ago

0.14.2

8 years ago

0.14.1

8 years ago

0.14.0

8 years ago

0.8.0

8 years ago

0.13.0

8 years ago

0.12.0

8 years ago

0.11.0

8 years ago

0.10.0

8 years ago

0.9.0

8 years ago

0.7.0

8 years ago