This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| app.post("/someUrl", function(req, res) { | |
| let IPAddress = req.ips; | |
| res.send(200).send({result: 'Success', tracePaths: IPAddress}); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| app.post("/someUrl", function(req, res) { | |
| res.send(200).send({result: 'Your request method', method: req.method}); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| app.post("/someUrl/:categoryId/:someName", function(req, res) { | |
| res.send(200).send({result: 'Your params as array', params: req.params}); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| app.use('/admin', function(req, res, next) { | |
| /* GET 'http://www.example.com/admin/new' */ | |
| console.log(req.originalUrl); // '/admin/new' | |
| console.log(req.baseUrl); // '/admin' | |
| console.log(req.path); // '/new' | |
| next(); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| app.post("/someUrl", function(req, res) { | |
| let protocol = req.protocol; | |
| if (protocol !== 'https') { | |
| res.status(426).send("Protocol Insecure"); | |
| } | |
| res.send(200).send({result: 'Success', protocol: protocol}); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| app.post("/someUrl/:categoryId/:someName", function(req, res) { | |
| // Request to /someUrl/12/gary?username=ganesh&password=shouldnotbehere | |
| res.send(200).send({result: 'Query params as object', queryParams: req.query}); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| app.get('/user/:id?', function userIdHandler(req, res) { | |
| console.log(req.route); | |
| res.send('GET'); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| app.post("/someUrl", function(req, res) { | |
| let protocol = req.secure; | |
| if (!protocol) { | |
| res.status(426).send("Protocol Insecure"); | |
| } | |
| res.send(200).send({result: 'Success', protocol: protocol}); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"}); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| app.post("/someUrl", function(req, res) { | |
| // Content-Type => "application/json" (Header Content-Type in request) | |
| let getContent = req.header('content-type'); | |
| if (getContent !== 'application/json') { | |
| res.status(406).send("Not Acceptable"); | |
| } | |
| // Raw buffer capture in request body (will be covered later) | |
| const contentBody = JSON.parse(req.body.toString('utf8')); | |
| res.send(200).send({result:"Success", content: contentBody}); | |
| }); |