Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
diogob committed May 17, 2024
1 parent 7123cea commit 4fce4ab
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const users = await response.json(usersSchema);
- [Transformers](#transformers)
- [Request transformers](#request-transformers)
- [Response transformers](#response-transformers)
- [Request timeout](#request-timeout)
- [Body](#body)
- [Query](#query)
- [Params](#params)
Expand Down Expand Up @@ -258,6 +259,24 @@ const response = await service.get("/users")
// response.statusText will be 'It worked!'
```

### Request timeout

A single timeout based on the service can be very useful since the default fetch timeout is quite long.
The `timeout` parameter accepts a number of milliseconds and abort any request that takes longer than that limit.

Using an [AbortController](https://developer.mozilla.org/en-US/docs/Web/API/AbortController) for individual requests is still possible for more fine grained control.

The example below will abort the request after 30 seconds rejecting the promise.

```ts
const service = makeService('https://example.com/api', {
timeout: 30000,
})

const response = await service.get("/users")

```

### Body
The function can also receive a `body` object that will be stringified and sent as the request body:

Expand Down

0 comments on commit 4fce4ab

Please sign in to comment.