Saturday 22 December 2018

What's the "proper" way to search using multiple options with a RESTful endpoint?

I'm teaching my self how to create RESTful endpoints using Express. My question is what's the "proper" to search for something using different criteria.​Example:In this first example, I want to search for a user by IDapp.get("/api-v1/users/:id", async (req, res) => {let id = req.params.id;res.send(await user.searchUserByID(id));});In this second example I want to search for a user by emailapp.get("/api-v1/users/:email", async (req, res) => {let email = req.params.email;res.status(await user.searchUserByEmail(email));});​The system doesn't know what I'm actually passing, it could be an id or an email.Should I create a more specific route?​/api-v1/users/id/:id"/api-v1/users/email/:email"​What is the "proper" convention for this? Does anyone have a link to industry best practices?Kind regards

Submitted December 22, 2018 at 05:09PM by sma92878

No comments:

Post a Comment