Is it better to have a separate function to handle GET and POST requests for the same API endpoint or combine them into one function that discriminates based on the existence of req.body or req.params?
i.e.
app.get('/api/profilepic', api.get_profilepic);
app.post('/api/profilepic', api.change_profilepic);
or:
app.get('/api/profilepic', api.profilepic);
app.post('/api/profilepic', api.profilepic);
If the latter, does Express.js provide a helper function to determine the request type? My approach so far to determine if req is POST requires an underscore:
if (_.size(req.body) == 0)
req.method
to see if it containsGET
orPOST
(or some other method, even). – Endostosisapp.all()
to handle both (and more) – Durning