Skip to content

Instantly share code, notes, and snippets.

@ganeshkbhat
Created October 4, 2018 03:08
Show Gist options
  • Select an option

  • Save ganeshkbhat/3284a0c1f5434d7e21258952c25ced5c to your computer and use it in GitHub Desktop.

Select an option

Save ganeshkbhat/3284a0c1f5434d7e21258952c25ced5c to your computer and use it in GitHub Desktop.
ExpressJS Series: Usage req.accepts
app.post("/someUrl", function(req, res) {
// Accept => "text/html" (Header Accept in request)
let returnContent = req.accepts(['json', 'text']);
// returns => 'json'
if (!returnContent) {
res.status(406).send("Not Acceptable");
}
res.send(200).send({result:"Some Result"});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment