Skip to content

create an unique interceptor instance #329

Closed Answered by kettanaito
smo043 asked this question in Q&A
Discussion options

You must be logged in to vote

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 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:

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@smo043
Comment options

Answer selected by kettanaito
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants