observable-json-rest-api-client
Send HTTP requests to JSON REST Web services; receive responses as RxJS Observables.
This package can send HTTP requests of type POST, GET, PUT, and DELETE; these types correspond to the CRUD operations (create, read, update, and delete) of a REST Web service. Any data sent is JSON, and attempts are made to parse any data received as JSON.
This package's API is:
request(httpMethod, urlString, requestData, verbose = false)
post(urlString, requestData, verbose = false)
get(urlString, verbose = false)
put(urlString, requestData, verbose = false)
delete(urlString, verbose = false)
post(), get(), put(), and delete() are merely convenience functions that call request() with a specific httpMethod.
Each function returns an RxJS Observable that yields an object with the following fields:
- statusCode : The HTTP status code from the response from the server
- statusMessage : The HTTP status message from the response from the server
- rawResponseBody : The raw body from the response from the server
- jsonResponseBody : The body from the response from the server after it has been parsed as JSON. This field is only present if the response body was successfully parsed as JSON.
- jsonParseError : The error, if any, that was encountered during the parsing of the response body as JSON.
Example 1: POST:
const engine = ; const postData = field1: 'abc' field2: 123; engine;
Example 2: GET:
const engine = ; engine;