Skip to content

Instantly share code, notes, and snippets.

@osvaldoM
Last active June 5, 2017 22:04
Show Gist options
  • Save osvaldoM/fdd61246eb27d218cb6249dcf991e2ea to your computer and use it in GitHub Desktop.
Save osvaldoM/fdd61246eb27d218cb6249dcf991e2ea to your computer and use it in GitHub Desktop.
fazendo requisição a uma API remota usando requestify
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