Last active
October 20, 2017 12:41
-
-
Save quentinchap/60b63747e410e77d18a278263843a696 to your computer and use it in GitHub Desktop.
Gist dans le cadre d'un article sur https://devotics.fr
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
// Chargement de la requête | |
var request = require('request'); | |
// Création d'une nouvelle route GET | |
app.get('/wikipedia', function(req, res) { | |
// Envoi d'une requête vers une api (GET) | |
request.get({ | |
url: "https://en.wikipedia.org/api/rest_v1/page/" | |
}, function(error, response, body) { | |
if (!error && response.statusCode == 200) { | |
// Si tout se passe bien, afficher le résultat | |
res.send(body); | |
} else { | |
// S'il y a une erreur envoyer error | |
res.send('error'); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment