README
NPM version">
Promise based XHR client with JSON as default.
Installation
npm install --save-dev jhr
Usage
This module attempts to treat AJAX/XHR requests as a function of http. Responses are typed for common http statuses (see the Response submodule) un-supported ones have the type Response.Untyped.
import * as Agent from 'jhr';
let agent = new jhr.Agent();
agent.get('http://example.com').
then((r:jhr.Response)=> {
if(r instanceof jhr.Response.Ok)
//it's ok
else if(r instanceof jhr.Response.Conflict)
//it's a conflict
else if(r instanceof jhr.Response.InternalServerError)
//it's serious
else
//it's a regular jhr.Response.Untyped
}).
catch(e=>{
//TransportError
});
License
Apache-2.0 © Lasana Murray