-
-
Notifications
You must be signed in to change notification settings - Fork 516
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
Set base URL for matching relative paths in request #397
Comments
Hi @mpittkin thanks for raising this :). I think that this can be implemented like @kettanaito has done for |
Hey, @mpittkin. Thanks for raising this. Please, how would you imagine this API? |
Hi @marcosvega91, @kettanaito.
That would probably be the simplest way, but the graphql implementation you linked above would offer more flexibility for mocking different APIs simultaneously. In order to keep the API consistent across both
|
I think that can be very useful. Do you wanna work on a PR ? It will be very awesome 🙈 |
The feature is sensible, yet I’m not sure whether the term “link” has any value in the REST world. Is there something close to what we are looking for in the REST spec/usage patterns? |
the only thing about |
I’d be happy to work on this issue, but I may need some guidance, as JS/TS is not my native language ;) Also I’m dealing with some family medical issues so I’m off work taking care of our kids right now, and won’t be able to work on it for a week or two. For the feature API, perhaps something like |
Let's try using the same |
Unfortunately, I have to close this. See the reasoning behind why this feature costs more than it brings. It's officially recommended to create a custom high-order function if you wish to reuse the same base path for multiple handlers. Like so: const github = (path) => {
return new URL(path, 'https://github.com').toString()
}
rest.get(github('/repos/:owner/:repo'), resolver) |
Is your feature request related to a problem? Please describe.
I have different API URLs for different environments, for instance in development it's
http://localhost:8080
where in production it's a relative path/api
. The paths are also different for Storybook, and I am using MSW in those as well.So right now I have to create the full request URL (absolute or relative) for all the MSW handlers, e.g.
Describe the solution you'd like
I'd like to be able to set a base URL for MSW, so that all relative paths are treated as extending from that, similar to the
baseURL
config property in Axios.Describe alternatives you've considered
The above approach works, but it's annoying to have to wrap every path with a function like that.
I also tried using wildcards like
*/users
, which works, but there is always the possibility that it would end up matching a different request, either from my application directly or from some other resource being pulled in from a library.The text was updated successfully, but these errors were encountered: