Skip to content
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

Using colon as a character instead of path parameter (express 5) #5610

Closed
Tanavya opened this issue Apr 18, 2024 Discussed in #5609 · 1 comment
Closed

Using colon as a character instead of path parameter (express 5) #5610

Tanavya opened this issue Apr 18, 2024 Discussed in #5609 · 1 comment

Comments

@Tanavya
Copy link

Tanavya commented Apr 18, 2024

Discussed in #5609

Originally posted by Tanavya April 18, 2024
I am trying to follow google's API design guide here for custom methods https://cloud.google.com/apis/design/custom_methods. I already looked through the discussion here #3857 but it did not solve my problem.

On express version 5.0.0-beta.3.

This works

router.get('/tasks/:id/([:])action', async (req, res, _next) => {
    const id = req.params["id"];
    return res.status(200).send(id);
  });

So I can do a simple GET on tasks/50/:action

However, the moment I remove the / it breaks.

router.get('/tasks/:id([:])action', async (req, res, _next) => {
    const id = req.params["id"];
    return res.status(200).send(id);
});

GET /tasks/50:action -> not found.

How do I solve this?

@Tanavya
Copy link
Author

Tanavya commented Apr 18, 2024

Oh interestingly, after some hit and trial I figured it out. Looks like this works:

router.get("/tasks/:id\\:action", async (req, res, _next) => {
  const id = req.params["id"];
  return res.status(200).send(id);
});

Now GET /tasks/50:action returns 200
Definitely documentation can be improved for this though.

@Tanavya Tanavya closed this as completed Apr 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant