Highwire
High level HTTP methods that are easy to build upon.
Reasoning
Superagent is a fantastic module, but I find that I generally need to wrap it up for use in a more functional approach. Highwire
provides this functional approach through simple HTTP methods that work great for building complex network layers, or just to make syncing your React components easier. They are meant to be wrapped in higher order functions to build complex network logic.
API
Highwire exposes an object with RESTful HTTP methods. Those methods are:
get(url [, options: { headers, query } ])
- url: full url of request
- options:
- headers: object of headers to attatch to request
- query: object of query parameters to attach to request (DO NOT USE: if url contains query params)
- timeout: cancel request after specified timeout (throws Error)
const headers = authorization: 'token <token>' const query = sortOrder: 'desc' const timeout = 3000
post(url, data [, options: { headers, query } ])
- url: full url of request
- data: body to send with request
- options:
- headers: object of headers to attatch to request
- query: object of query parameters to attach to request (DO NOT USE: if url contains query params)
- timeout: cancel request after specified timeout (throws Error)
- progress: function that is called on progress event of request; returns:
{ direction: string, lengthComputable: boolean, loaded: number, total: number }
const headers = authorization: 'token <token>' const timeout = 3000const progress = console)const user = name: 'highwire'
put(url, data [, options: { headers, query } ])
- url: full url of request
- data: body to send with request
- options:
- headers: object of headers to attatch to request
- query: object of query parameters to attach to request (DO NOT USE: if url contains query params)
- timeout: cancel request after specified timeout (throws Error)
const headers = authorization: 'token <token>' const timeout = 3000 User
patch(url, data [, options: { headers, query } ])
- url: full url of request
- data: body to send with request
- options:
- headers: object of headers to attatch to request
- query: object of query parameters to attach to request (DO NOT USE: if url contains query params)
- timeout: cancel request after specified timeout (throws Error)
const headers = authorization: 'token <token>' const timeout = 3000 User
del(url, [, options: { headers, query } ])
- url: full url of request
- options:
- headers: object of headers to attatch to request
- query: object of query parameters to attach to request (DO NOT USE: if url contains query params)
- timeout: cancel request after specified timeout (throws Error)
const headers = authorization: 'token <token>' const timeout = 3000 User
multipart(url, { meta: fields, attachments } [, options: { headers, query, progress }])
- url: full url of request
- meta:
- fields[[name, value]] any form fields to attach to request
- attachments[[name, path, filename]]: any attachments to attach to request
- options:
- headers: object of headers to attatch to request
- query: object of query parameters to attach to request (DO NOT USE: if url contains query params)
- timeout: cancel request after specified timeout (throws Error)
- progress: function that is called on progress event of request; returns:
{ direction: string, lengthComputable: boolean, loaded: number, total: number }
const attachments = 'profile' './tmp/profile.jpg'const progress = consoleconst timeout = 5000 User