Created
October 23, 2017 17:22
-
-
Save JacopoMangiavacchi/099c1417e2ece29a6023cb1bcdf7e0f8 to your computer and use it in GitHub Desktop.
Javascript - Node.js Express.js Rest Test : <- Post <- Request <- Get
This file contains 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
var express = require('express'); | |
var app = express(); | |
var bodyParser = require('body-parser'); | |
var request = require('request'); | |
app.use(bodyParser.urlencoded({ extended: true })); | |
app.use(bodyParser.json()); | |
var router = express.Router(); | |
router.get('/language', function(req, res) { | |
res.json({ language: 'javascript' }); | |
}); | |
router.post('/request', function(req, res) { | |
request(req.body.url, function (error, response, body) { | |
if (!error) { | |
res.json({ language: JSON.parse(body).language }); | |
} | |
}); | |
}); | |
app.use('/', router); | |
app.listen(8090); | |
console.log('server is listening on port 8090'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment