A Mapbox API request.
Note that creating a MapiRequest does not send the request automatically.
Use the request's send method to send it off and get a Promise.
The emitter property is an EventEmitter that emits the following events:
'response'- Listeners will be called with aMapiResponse.'error'- Listeners will be called with aMapiError.'downloadProgress'- Listeners will be called withProgressEvents.'uploadProgress'- Listeners will be called withProgressEvents. Upload events are only available when the request includes a file.
emitterEventEmitter An event emitter. See above.clientMapiClient This request'sMapiClient.response(MapiResponse | null) If this request has been sent and received a response, the response is available on this property.error(MapiError | Error | null) If this request has been sent and received an error in response, the error is available on this property.abortedboolean If the request has been aborted (viaabort), this property will betrue.sentboolean If the request has been sent, this property will betrue. You cannot send the same request twice, so if you need to create a new request that is the equivalent of an existing one, useclone.pathstring The request's path, including colon-prefixed route parameters.originstring The request's origin.methodstring The request's HTTP method.queryObject A query object, which will be transformed into a URL query string.paramsObject A route parameters object, whose values will be interpolated the path.headersObject The request's headers.body(Object | string | null) Data to send with the request. If the request has a body, it will also be sent with the header'Content-Type: application/json'.file(Blob | ArrayBuffer | string | ReadStream) A file to send with the request. The browser client accepts Blobs and ArrayBuffers; the Node client accepts strings (filepaths) and ReadStreams.encodingstring The encoding of the response.sendFileAsstring The method to send thefile. Options aredata(x-www-form-urlencoded) orform(multipart/form-data).
Get the URL of the request.
accessTokenstring? By default, the access token of the request's client is used.
Returns string
Send the request. Returns a Promise that resolves with a MapiResponse.
You probably want to use response.body.
send only retrieves the first page of paginated results. You can get
the next page by using the MapiResponse's nextPage
function, or iterate through all pages using eachPage
instead of send.
Returns Promise<MapiResponse>
Abort the request.
Any pending Promise returned by send will be rejected with
an error with type: 'RequestAbortedError'. If you've created a request
that might be aborted, you need to catch and handle such errors.
This method will also abort any requests created while fetching subsequent
pages via eachPage.
If the request has not been sent or has already been aborted, nothing will happen.
Invoke a callback for each page of a paginated API response.
The callback should have the following signature:
(
error: MapiError,
response: MapiResponse,
next: () => void
) => voidThe next page will not be fetched until you've invoked the
next callback, indicating that you're ready for it.
callbackFunction
Clone this request.
Each request can only be sent once. So if you'd like to send the same request again, clone it and send away.
Returns MapiRequest A new MapiRequest configured just like this one.
A Mapbox API response.
bodyObject The response body, parsed as JSON.rawBodystring The raw response body.statusCodenumber The response's status code.headersObject The parsed response headers.linksObject The parsed response links.requestMapiRequest The response's originatingMapiRequest.
Check if there is a next page that you can fetch.
Returns boolean
Create a request for the next page, if there is one.
If there is no next page, returns null.
Returns (MapiRequest | null)
A Mapbox API error.
If there's an error during the API transaction,
the Promise returned by MapiRequest's send
method should reject with a MapiError.
requestMapiRequest The errored request.typestring The type of error. Usually this is'HttpError'. If the request was aborted, so the error was not sent from the server, the type will be'RequestAbortedError'.statusCodenumber? The numeric status code of the HTTP response.body(Object | string)? If the server sent a response body, this property exposes that response, parsed as JSON if possible.messagestring? Whatever message could be derived from the call site and HTTP response.
A low-level Mapbox API client. Use it to create service clients that share the same configuration.
Services and MapiRequests use the underlying MapiClient to
determine how to create, send, and abort requests in a way
that is appropriate to the configuration and environment
(Node or the browser).
accessTokenstring The Mapbox access token assigned to this client.originstring? The origin to use for API requests. Defaults to https://api.mapbox.com.