Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adhere to Fetch API "Request" in response resolver #1316

Merged
merged 12 commits into from
Jul 11, 2022

Conversation

kettanaito
Copy link
Member

@kettanaito kettanaito commented Jul 9, 2022

GitHub

Changes

Warning
Deprecates req.body. Explicit request body reading methods must be used instead.

  • Makes the req instance in the handler more compliant with Fetch API's Request.
  • Migrates over to extend IsomorphicRequest from the Interceptors that now has methods like text(), json() and arrayBuffer() to read request body as respective data types.
rest.post('/user', async (req, res, ctx) => {
  const json = await req.json()
})

Dependency updates

Roadmap

  • Add integration tests for the new request methods:
  • req.text()
  • req.json()
  • req.arrayBuffer()

@codesandbox-ci
Copy link

codesandbox-ci bot commented Jul 9, 2022

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit b4ad14c:

Sandbox Source
MSW React Configuration

@95th 95th marked this pull request as ready for review July 9, 2022 16:07
src/handlers/RestHandler.ts Outdated Show resolved Hide resolved
src/utils/request/MockedRequest.ts Outdated Show resolved Hide resolved
src/utils/request/MockedRequest.ts Outdated Show resolved Hide resolved
src/utils/request/MockedRequest.ts Outdated Show resolved Hide resolved
@kettanaito
Copy link
Member Author

Thank you once again for shaping this up, @95th! I will take a look at this tomorrow/Monday. Let's make this change happen!

@kettanaito kettanaito added the BREAKING CHANGE Pull request introducing breaking changes. label Jul 11, 2022
@kettanaito kettanaito merged commit fc7f00c into main Jul 11, 2022
@kettanaito kettanaito deleted the feat/request-api branch July 11, 2022 13:17
@kettanaito
Copy link
Member Author

Released: v0.44.0 🎉

This has been released in v0.44.0!

Make sure to always update to the latest version (npm i msw@latest) to get the newest features and bug fixes.


Predictable release automation by @ossjs/release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BREAKING CHANGE Pull request introducing breaking changes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Access raw request body as buffer
2 participants