- Introduction
- Quick start
- Philosophy
- Comparison
- Default behaviors
- Limitations
- Debugging runbook
- FAQ
- Mocking HTTP
- Mocking GraphQL
- Mocking WebSocket
- Integrations
- API
- CLI
- Best practices
- Recipes
Redirects
Mocking redirect responses.
You can mock a redirect response by constructing a valid redirect Response instance and returning it from the response resolver. This implies setting a redirect status code (3xx) and the location header that points to the destination URL.
http.get('/resource-a', () => {
return new HttpResponse(null, {
status: 301,
headers: {
location: '/resource-b',
},
})
})In this example, the
GET /resource-arequest will be redirected to/resource-b, which in this scenario is unhandled. You can define a request handler for it, too, and it will be matched as usual!