The intent of this module is to provide a low level utility providing rxjs
wrapping of node core http/https
off of which higher level abstractions can be built.
-
RxHttpRequest(options)
- aSubject
wrappinghttp.ClientRequest
.raw
- the underlyinghttp.ClientRequest
object.
-
RxHttpsRequest(options)
- aSubject
wrappinghttp.ClientRequest
forhttps
.raw
- the underlyinghttp.ClientRequest
object.
As subjects, complete
must be called (similar to end
on a request), to begin the request.
As observables, requests emit RxReadable
observable responses.
RxReadable
- anObservable
wrappinghttp.IncomingMessage
.raw
- the underlyinghttp.IncomingMessage
.
This observable emits data read off the http.IncomingMessage
stream.
const request = new RxHttpRequest({
method: 'GET',
hostname: 'example.com',
path: '/hello'
});
request
//project the incoming response observable
.flatMap((response) => response)
//gather all data read off the response
.toArray()
//parse the body (JSON in this case)
.map((chunks) => JSON.parse(Buffer.concat(chunks)))
.subscribe(
(body) => {
console.log(body);
},
(error) => {
console.error(error);
},
() => {
console.log('request complete');
}
);
//Begins the request
request.complete();