docs: fix typo

This commit is contained in:
Bereket Engida
2024-09-28 21:35:30 +03:00
parent 233b8c6db3
commit fd52fde752
3 changed files with 2 additions and 7 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 851 KiB

After

Width:  |  Height:  |  Size: 820 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 659 KiB

After

Width:  |  Height:  |  Size: 617 KiB

View File

@@ -190,16 +190,14 @@ If you throw an `APIError` from the middleware or returned a `Response` object,
Additional to middlewares you can also hook into right before a request is made and right after a response is returned. This is mostly useful if you wnat to do something that affects all requests or responses.
### On Request
#### On Request
The `onRequest` function is called right before the request is made. It takes two parameters: the `request` and the `context` object.
Heres how it works:
- **Continue as Normal**: If you don't return anything, the request will proceed as usual.
- **Interrupt the Request**: To stop the request and send a response, return an object with a `response` property that contains a `Response` object.
- **Modify the Request**: You can also return a modified `request` object to change the request before it's sent.
```ts title="plugin.ts"
@@ -211,14 +209,13 @@ const myPlugin = {
}
```
### On Response
#### On Response
The `onResponse` function is executed immediately after a response is returned. It takes two parameters: the `response` and the `context` object.
Heres how to use it:
- **Modify the Response**: You can return a modified response object to change the response before it is sent to the client.
- **Continue Normally**: If you dont return anything, the response will be sent as is.
```ts title="plugin.ts"
@@ -268,9 +265,7 @@ const myPlugin = {
#### When to use Middelware, Hooks, On Request, On Response
- **Middlewares**: You should use middlewares when you want to use a route matcher to target a group of routes.
- **Hooks**: You should use hooks when you want to target a specific route or request.
- **On Request & On Response**: You should use on request and on response when you want to do something that affects all requests or responses.
### Rate Limit