createHttpService API
These docs are auto-generated from typings files (
*.d.ts
).
HttpParams
If you're looking for the params for the http
calls inside a fetch factory's request, you've
found 'em!
e.g.
const makePersonFetch = defineFetch({
displayName: 'Get Person',
make: personId => ({
request: () => ({ http }) =>
http({
// see below for what can go here
// ๐๐๐๐๐
})
})
});
The HTTP Service uses superagent behind the scenes.
Name | Description | Type | Required |
---|---|---|---|
method | The HTTP method to use. | 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | yes |
route | The route to use. | string | yes |
query | An object representing the query parameters to serialize to the URL.{foo: ['bar', 'baz'], hello: 'world'} ==> ?foo=bar&foo=baz&hello=world | { [key: string]: string } | no |
data | The data to be sent to the URL. If this is an object, it will be serialized to JSON. Sending a FormData object is also supported. | any | no |
ok | This is directly upstream's .ok method:http://visionmedia.github.io/superagent/#error-handling "Alternatively, you can use the .ok(callback) method to decide whether a response is anerror or not. The callback to the ok function gets a response and returns true if theresponse should be interpreted as success." | (response: request.Response) => boolean | no |
req | You can add custom behavior to the superagent req using this callback.it is added before the req.send method is called | (request: request.SuperAgentRequest) => void | no |
createHttpService
Give the required HttpServiceParams
, this function returns an HTTP service ready to be put into
the services
object in createDataService
.
function createHttpService(params: HttpServiceParams): HttpService;
HttpServiceParams
The params that can be passed into the createHttpService
function.
Name | Description | Type | Required |
---|---|---|---|
getHeaders | Provide a function to the HTTP service to return headers for the request. Use this to inject any authentication tokens. | (() => any) | (() => Promise) | no |
prefix | Use this to prefix all requests with a certain path. e.g. /api | string | no |
getPrefix | Use this to dynamically determine the prefix. | (() => string) | (() => Promise) | no |
proxies | Pass any proxies into the HTTP service here. Create the proxy withcreateHttpProxy first. | HttpProxy[] | no |