Replies: 1 comment
-
Hi, @xylude 👋 Thank you for your feedback. The Request Handler page is indeed meant to be a light introduction into the concept like you've said. Whenever you are describing an API, I encourage you read one of the "Describing X" pages: Those go into the detail you seek on how to work with requests and responses. For example, here's a section on "Request request body" from the "Describing REST API" page: // src/mocks/handlers.js
import { http, HttpResponse } from 'msw'
const allPosts = new Map()
export const handlers = [
http.post('/posts', async ({ request }) => {
// Read the intercepted request body as JSON.
const newPost = await request.json()
// Push the new post to the map of all posts.
allPosts.set(newPost.id, newPost)
// Don't forget to declare a semantic "201 Created"
// response and send back the newly created post!
return HttpResponse.json(newPost, { status: 201 })
}),
] The page is also referenced in the "Using request handlers" section on "Request handlers" page. Is there something I can do to make it more discoverable? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Feedback
I feel as if it's been pretty difficult to suss out what is actually passed in to the handler functions. I'm on the 'Request Handler' documentation page and it's very light and implies stuff is passed in but then neglects to explain what or what the shape of those objects are. Right now I'm just trying to work out how to get items off the JSON request body in post requests and can't easily locate it. I've also looked at the 'Intercepting Requests' and 'Request Namespace' pages and still can't find it.
Beta Was this translation helpful? Give feedback.
All reactions