I try to create create 2 endpoints, which differ by Query String.Ej:
/movie?genre=1 /movie?order=desc
When consuming the endpoint, it only enters the first one (order), the other does not enter. What I try is that if the gender is sent (by query) I execute a service, and if I send the order (by query) I execute the other
router.get('/movies', async (req, res) => {
const { order } = req.query;
})
gender=1
router.get('/movies', async (req, res) => {
const { genre } = req.params;
})
There are two things... first, you must not have two endpoints (the endpoint is the same: '/movies'... A different query string does not make it a different endpoint). Second, the query parameters go at the end of the URL, and you can put as many as you like. The query should really be
/movies?genero=1&orden=desc
. At the `/movies' endpoint you can check what parameters come in the query, and process your data accordingly:In case gender or order do not come in the query, its value will be
undefined
.