Exact paths with colon #739
Replies: 2 comments 1 reply
-
Hey, @SimeonRolev. Thanks for reaching out. Colons are reserved for URL path parameters, so While a colon (
Perhaps consider remodeling your resource URLs to drop the colons, if possible? The only way to allow exact colons in a request handler's URL, for now, is to convert the entire URL string into a RegExp: rest.get(/\/rest\/o:example\/p:example/, (req, res, ctx) => {}) We are unlikely to handle colons exactly because they are reserved for path parameters. Deciding between an exact usage and a parameter is a guessing game that the library mustn't do. |
Beta Was this translation helpful? Give feedback.
-
For anyone struggling with this, you can escape the colon by prepending two forward slashes to it. // Used to match '/api/v1/resource:action'
rest.post('/api/v1/resource\\:action', (req, res, ctx) => res(ctx.json({ ... }))) This method of escaping the character is used internally in the library to escape the colon before the protocol and the one before the port number see here There's little choice for me as my company follows this google standards for custom methods to build its APIs, hence, I have to intercept many endpoints with colons in them. |
Beta Was this translation helpful? Give feedback.
-
Hi, guys!
I checked the documentation, sorry if I missed it. I didn't find a simple way to pass exact path, that includes colons. Can I bypass the
Path with parameters
parsing that is described here https://mswjs.io/docs/basics/request-matching ?For example, I'd like a handler like this:
I want it to behave like an exact path, without parsing the
o:
andp:
as parameters.Thanks in advance!
As a workaround, I came up with this. Create a response map with
<url>:<data>
and do the match yourself inside the handler.Beta Was this translation helpful? Give feedback.
All reactions