Skip to content

Instantly share code, notes, and snippets.

@JacopoMangiavacchi
Created October 23, 2017 17:22
Show Gist options
  • Save JacopoMangiavacchi/099c1417e2ece29a6023cb1bcdf7e0f8 to your computer and use it in GitHub Desktop.
Save JacopoMangiavacchi/099c1417e2ece29a6023cb1bcdf7e0f8 to your computer and use it in GitHub Desktop.
Javascript - Node.js Express.js Rest Test : <- Post <- Request <- Get
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