- Introduction
- Quick start
- Philosophy
- Comparison
- Default behaviors
- Limitations
- Debugging runbook
- FAQ
- Mocking HTTP
- Mocking GraphQL
- Mocking WebSocket
- Integrations
- API
- CLI
- Best practices
- Recipes
Request body
Read the intercepted request's body.
You can read the intercepted request’s body as you normally would any Fetch API Request
. The request
object you get in the response resolver argument is literally a regular Request
instance and can be operated as such.
For example, you can call await request.json()
to read the request’s body as JSON:
http.post<{ id: string }, Post>('/posts/:id', async ({ request }) => {
const newPost = await request.clone().json() // Post
})
It’s highly recommended to clone the intercepted request before reading its body. While it’s okay to read the request body directly if you plan to mock its response, reading it without cloning in passthrough/bypass scenarios will result in an exception (streams cannot be read twice).
The same is true for the other methods like .text()
, .formData()
, .blob()
, etc.