0.0.9 • Published 7 years ago

@funkybob/request v0.0.9

Weekly downloads
9
License
MIT
Repository
-
Last release
7 years ago

funky-request

Simple Promise wrapper for XHR

request.request(url, options)

Options:

  • method : GET | POST | ...
  • data : post body
  • form : form element to POST
  • headers: {}
  • query:

If form is provided, it will override data, and a FormData instance will be constructed with it.

If provided, data will be encoded according to the 'Content-Type' header. If it is 'application/json', then data will be JSON encoded. Otherwise, URL encoding will be applied.

request.defaultHeaders = {}

Any values added to this Object will be set as Headers on all requests.

request.prepareHeaders(headers)

A hook to allow a callable to inspect and modify headers before each request.

request.json(url, options)

Automatically decodes successful responses from JSON.

request.rpc(url, method, data)

Sets 'Content-Type' as 'application/json', passes method in a 'X-RPC-Action' header, and JSON decodes the response.

request.RequestError

All errors are raised using this class.

Properties:

  • message: the Method and URL of the request
  • errorType: one of 'error', 'timeout', or 'abort'
  • xhr : the XMLHttpRequest instance
0.0.9

7 years ago

0.0.8

7 years ago

0.0.7

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago