Cloudflare HTTP Util
This utility library is a simple interface that hides away the client-side http implementation being used so that it can easily be swapped out for something else.
$ npm install cf-util-http
http.request(method, url, [opts], [callback])
Perform an HTTP request.
const abortRequest = http;;
||Required. The HTTP method type for the request.|
||Required. The url to make the request.|
||Optional. Options for the request.|
||Optional. Parameters to be serialized into the url.|
||Optional. Headers to send with the request.|
||Optional. The body of the request.|
||Callback to call when request is complete.|
http.request will return an abort function that you can call to stop the
request from being made.
The callback will receive two arguments:
res which will both have
the following shape (if they are not
headers: ...status: 200body: ...text: '...'
These are all shorthands to
http.request that don't require passing a
Modify a request before it is sent. This can be useful for authentication or other middleware.
callback will be called with a single argument
opts that you can mutate
before a request will be created.
opts will have the following shape:
method: 'POST'url: '/posts'// Headers to be sent along with the requestheaders:Accept: 'application/json'// Parameters to be serialized as `?page=1&limit=20` and appended to the urlparameters:page: 1limit: 20// Body of the request being sentbody:title: 'A New Post'content: 'Contents of the new post.'
body may not exist depending on the
request being made.