create an unique interceptor instance #329
-
I am looking for a method that works similarly to axios.create. How should I use this library to achieve a similar approach like Axios? Kindly assist. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hey, @smo043. MSW works on an endpoint basis. Using Request handlers, you can describe the network you want on the request/response basis. import { http, HttpResponse } from 'msw'
const handlers = [
http.post('/login', () => HttpResponse.json({ success: true }))
] I highly recommend you go through our docs, they will teach you everything to Get started with MSW. If you are referring particularly to the encapsulation that |
Beta Was this translation helpful? Give feedback.
Hey, @smo043.
MSW works on an endpoint basis. Using Request handlers, you can describe the network you want on the request/response basis.
I highly recommend you go through our docs, they will teach you everything to Get started with MSW.
If you are referring particularly to the encapsulation that
axios.create()
does, I believe the only thing transferrable from there to MSW is the base URL. MSW doesn't have a designated API for handling base URLs but you can do that easily yourself: