Custom HTTP methods #1196
-
ScopeAdds a new behavior Compatibility
Feature descriptionSome services that I have been mocking, such as Vault, use custom HTTP methods like I think it would useful to be able to register custom HTTP methods, currently I have to use The API could be something as simple as |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
Hey, @connorjburton. You can create your own // my-rest.js
import { rest as defaultRest, RestHandler } from 'msw'
function list(path, resolver) {
return new RestHandler('list', path, resolver)
}
export const rest = {
...defaultRest,
list,
} And then use it in your handlers: import { rest } from './my-rest'
rest.list('/resource', resolver) |
Beta Was this translation helpful? Give feedback.
-
Thank you! Is this documented anywhere? I couldn't find anything like this on the docs. Maybe it's worth adding as a recipe? |
Beta Was this translation helpful? Give feedback.
-
I'm writing a recipe on this but it's not ready just yet. The topic is quite complex as you can build a lot of customization using our existing API. I'm also working on the next version of the documentation, and this recipe will likely be included there. |
Beta Was this translation helpful? Give feedback.
Hey, @connorjburton.
You can create your own
rest.list()
request handler like so:And then use it in your handlers: