Last active
June 5, 2017 22:04
-
-
Save osvaldoM/fdd61246eb27d218cb6249dcf991e2ea to your computer and use it in GitHub Desktop.
fazendo requisição a uma API remota usando requestify
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
var express = require('express'), | |
app = express(), | |
port = process.env.PORT || 3000; | |
/* | |
aqui importo o requestify(biblioteca para acedrer a API's remotas através de requisições HTTP) | |
primeiro tens de fazer: npm install requestify | |
*/ | |
var requestify = require('requestify'); | |
app.listen(port); | |
app.route('/') | |
.get(function(req,res){ | |
//faco o request aqui | |
requestify.get('https://jsonplaceholder.typicode.com/posts').then(function(response) { | |
// Get the response body | |
var content=response.getBody(); | |
//devolvoo resultado | |
res.json(content); | |
}); | |
}); | |
console.log('todo list RESTful API server started on: ' + port); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment