kaeedo / typed-rest-client

Node Rest and Http Clients with typings for use with TypeScript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Typed Rest and Http Client with TypeScript Typings

A lightweight Rest and Http Client optimized for use with TypeScript with generics and async await.

Status

With 0.9 just published, we believe the API surface for 1.0 has settled. More testing in progress then we will release 1.0.

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
  • Proxy support
  • Certificate support (Self-signed server and client cert)
  • Redirects supported

Intellisense and compile support from typing the REST calls: intellisense

Install the library

npm install typed-rest-client --save

Samples

See samples for complete coding examples

Also see 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. It's 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.

Contributing

To contribute to this repository, see the contribution guide

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.

About

Node Rest and Http Clients with typings for use with TypeScript

License:Other


Languages

Language:TypeScript 75.4%Language:JavaScript 24.6%