|
| 1 | +--- |
| 2 | +title: HTTP Options |
| 3 | +sidebar_position: 7 |
| 4 | +--- |
| 5 | + |
| 6 | +Various options can be passed to the HTTP client on each request. These options can be used to customize the behavior of the HTTP client, such as setting headers, timeouts, and more. |
| 7 | + |
| 8 | +## Options |
| 9 | + |
| 10 | +### `method` |
| 11 | + |
| 12 | +The HTTP method to be used for the request. It's `GET` by default and can also be `POST`, `PUT`, `DELETE`, `PATCH`, `HEAD`, `OPTIONS`, or `TRACE`. |
| 13 | +This can also be set with the [`withMethod`](./builder#withmethod) method of the builder. |
| 14 | + |
| 15 | +### `baseUrl` |
| 16 | + |
| 17 | +The base URL to be used to construct the URL of the request. This option is prepended to the `path` if it's not an absolute URL. |
| 18 | +It is useful for setting a common base URL for all requests, such as an API endpoint. |
| 19 | +This can also be set with the [`withBaseUrl`](./builder#withbaseurl) method of the builder. |
| 20 | + |
| 21 | +### `path` |
| 22 | + |
| 23 | +The path to the resource. This is a required option. It can be an absolute URL or a relative URL. If it's a relative URL, it will be prepended with the `baseUrl` option. |
| 24 | +This can also be set with the [`withPath`](./builder#withpath) method of the builder. |
| 25 | + |
| 26 | +### `params` |
| 27 | + |
| 28 | +The path can contain path parameters, which are replaced with the values passed in the `params` option. |
| 29 | +The path parameters are defined with the `:paramName` syntax. |
| 30 | +For example, if the path is `/users/:id`, and the `params` option is `{ id: 1 }`, the final URL will be `/users/1`. |
| 31 | +The typing and default params can be set with the [`withParams`](./builder#withparams) method of the builder. |
| 32 | + |
| 33 | +### `search` |
| 34 | + |
| 35 | +The search parameters to be added to the URL. This option is an object with the parameter names as keys and the parameter values as values. |
| 36 | +The search parameters are added to the URL as a query string. For example, if the path is `/users`, and the `search` option is `{ id: 1 }`, the final URL will be `/users?id=1`. |
| 37 | +The typing and default search parameters can be set with the [`withSearch`](./builder#withsearch) method of the builder. |
| 38 | + |
| 39 | +### `headers` |
| 40 | + |
| 41 | +The headers to be sent with the request. This option is an object with the header names as keys and the header values as values. |
| 42 | +The typing and default headers can be set with the [`withHeaders`](./builder#withheaders) method of the builder. |
| 43 | + |
| 44 | +### `body` |
| 45 | + |
| 46 | +The body of the request. This option can be a string, an object, or a buffer. If it's an object, it will be serialized to JSON and the `Content-Type` header will be set to `application/json`. |
| 47 | +The typing and default body can be set with the [`withBody`](./builder#withbody) method of the builder. |
| 48 | + |
| 49 | +### `meta` |
| 50 | + |
| 51 | +The meta information to be sent with the request. |
| 52 | +The typing and default meta can be set with the [`withMeta`](./builder#withmeta) method of the builder. |
| 53 | + |
| 54 | +### `responseType` |
| 55 | + |
| 56 | +The type of the response. This option can be `json`, `text`, `blob`, `arraybuffer`, or `response`. The default may be inferred from the response or be `json` if it can't be inferred. |
| 57 | + |
| 58 | +### `timeout` |
| 59 | + |
| 60 | +The timeout for the request in milliseconds. If the request takes longer than this time, it will be aborted. |
| 61 | +The default timeout is `0`, which means no timeout. |
| 62 | + |
| 63 | +### `delay` |
| 64 | + |
| 65 | +The request will be delayed by the specified number of milliseconds. |
| 66 | +Useful for debouncing requests that might be triggered multiple times in a short period of time. |
| 67 | +Can also be used to simulate slow network. |
| 68 | + |
| 69 | +### `abortable` |
| 70 | + |
| 71 | +Whether the request can be aborted. If this option is `true`, the request will be aborted if query is cancelled. |
| 72 | + |
| 73 | +### `concurrency` |
| 74 | + |
| 75 | +An object accepting optional `limit` and `key` properties. |
| 76 | + |
| 77 | +- `key`: The key to be used to identify the pool the request belongs to. Concurrent requests with the same key will be grouped together and share the same pool. Can be left empty to use the default pool. |
| 78 | +- `limit`: The maximum number of concurrent requests in the pool. If the limit is reached, the request will be queued until a slot is available. There is no limit by default. |
| 79 | + |
| 80 | +### `key` |
| 81 | + |
| 82 | +Additional key that will be used to identify the request. When the key changes, the request will be refetched. |
0 commit comments