Skip to content

Instantly share code, notes, and snippets.

@coco98
Last active May 28, 2017 07:15
Show Gist options
  • Save coco98/5dfb00e75ef132a9a6c58644928a4eed to your computer and use it in GitHub Desktop.
Save coco98/5dfb00e75ef132a9a6c58644928a4eed to your computer and use it in GitHub Desktop.
Nodejs service on Hasura making an API request to another API on Hasura
const fetch = require('isomorphic-fetch');
const express = require('express');
const app = express();
//your routes here
app.get('/hello', function (req, res) {
const url = 'http://api2.default/respond';
const options = {
method: 'GET'
};
fetch(url, options).then(
(response) => {
if (response.ok) {
response.text().then(
(t) => {
// Send the response received from api2
res.send(t);
});
} else {
res.status(500)
.send('Error from api2: ' + response.status.toString());
}
},
(error) => {
console.error(error);
res.status(500).send('Internal error contacting api2');
});
});
app.listen(8080, function () {
console.log('Example app listening on port 8080!');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment