-
-
Notifications
You must be signed in to change notification settings - Fork 16.4k
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
How to use colon as normal character instead of route param #3857
Comments
If you use Koa koa-router, try Reason: |
Hello is this not working yet or maybe express have done an update to done this. |
You can define your route using the double colon notation and a switch statement to execute the appropriate logic based on your action. app.put('/tasks/:id::action', function (req, res) {
switch (req.params.action) {
case "delete":
return res.send("deleted")
case "update":
return res.send("updated")
default:
return res.send("invalid action")
}
}) |
@kevinrambaud Do you know if there's a way to do this without having to do a match on the command itself? So, if I wanted to have actual physical routes for the different actions (/tasks/1:publish) without having the sub-routing logic? |
Through trial and error, and from the express routing document guidance for treatment of $, I ended up with the following that appears to work: app.put('/tasks/:id[:]action', function (req, res) {}); If the dev team has any comment if that's the best way, that would be great, but seems to work. Thanks! |
@patwhite You might want to open an issue at https://github.com/pillarjs/path-to-regexp to get a more definitive answer. |
Well the expressJS docs addressed this
|
Colon(:) used to define route param in Express/Koa.
Google API design use colon as custom verb
Question: Is there a way to define a route in which I want use colon as normal character ?
Target: define a route that match
PUT /tasks/1234:undelete
, and define with string instead of regexp.The text was updated successfully, but these errors were encountered: