# bun/no-unbounded-requests

> Require an axios request to have a `timeout` or a `signal`

By default axios has no timeout. If the server accepts the connection and never answers, the promise never settles, and anything that awaits it hangs. Set `timeout`, or pass a `signal` that ends the request.

The rule looks at `axios()`, `axios.request()`, `axios.create()`, and methods such as `axios.get()` and `axios.post()`. A `timeout` of `0` or `Infinity` is reported too, because it sets no limit.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

Off by default. To turn it on:

```toml bunfig.toml
[lint.rules]
"bun/no-unbounded-requests" = "error" # or "warn"
```

Every option, set to its default:

```toml bunfig.toml
[lint.rules]
"bun/no-unbounded-requests" = ["error", {
  clients = [], # list of objects
}]
```

{/* End of the generated section. */}

## Examples

Reported:

{/* bad {"count": 3} */}
```js
import axios from "axios";

const user = await axios.get(`/users/${id}`);
await axios.post("/users", user, { headers });
const api = axios.create({ baseURL: "https://api.example.com", timeout: 0 });
```

Not reported:

{/* good */}
```js
import axios from "axios";

const user = await axios.get(`/users/${id}`, { timeout: 5000 });
await axios.post("/users", user, { headers, signal: AbortSignal.timeout(5000) });
const api = axios.create({ baseURL: "https://api.example.com", timeout: 5000 });
```

A file that sets a default timeout isn't checked:

{/* good */}
```js
import axios from "axios";

axios.defaults.timeout = 5000;

const user = await axios.get(`/users/${id}`);
```

A config with `cancelToken` passes too. A config that's a variable, or that spreads another object, isn't checked, because the rule can't see what's in it. For an instance, the `axios.create()` call is checked and the requests made with it aren't.

{/* good */}
```js
import axios from "axios";

await axios.get("/users", requestConfig);
await axios.get("/users", { ...requestConfig, params });

const api = axios.create({ timeout: 5000 });
await api.get("/users");
```

## Options

| Option | Default | What it does |
| --- | --- | --- |
| `clients` | `[]` | More modules that export something you call like `axios`. Each entry is `{ module, names }`, with the import specifier and the export names. Without `names`, the default export is the client. |

```toml bunfig.toml
[lint.rules]
"bun/no-unbounded-requests" = ["error", {
  clients = [{ module = "./http.js", names = ["api"] }],
}]
```

{/* bad {"options": [{"clients": [{"module": "./http.js", "names": ["api"]}]}]} */}
```js
import { api } from "./http.js";

const users = await api.get("/users");
```

{/* bad {"options": [{"clients": [{"module": "./http.js"}]}]} */}
```js
import api from "./http.js";

const users = await api.get("/users");
```
