Let’s say I have this GET url in my REST service:
router.get('/api/platform/:type', async (req, res) => {
// something
}
I only want the request if :type
is "windows" or "android". are there any way to do this in the url definition?
I think I’ve seen something like this before:
router.get('/api/platform/:type{windows|android}', async (req, res) => {
// something
}
Something like that but it doesn’t quite work for me.
2
Answers
You could probably use a regular expression:
See Path examples; Type: "Regular Expression"
Here is a regex example in native JS to test out the route expression:
You can append a regular expression in parentheses to a route parameter to validate its format:
https://expressjs.com/en/guide/routing.html