Skip to content

Instantly share code, notes, and snippets.

@Ramko9999
Last active May 25, 2020 17:20
Show Gist options
  • Save Ramko9999/0d772aa284ccf25b28f354016b5f5229 to your computer and use it in GitHub Desktop.
Save Ramko9999/0d772aa284ccf25b28f354016b5f5229 to your computer and use it in GitHub Desktop.
const express = require("express");
const app = express();
const TigerGraphCred = require("./config.js");
const fetch = require("node-fetch");
app.get("/profile/:id", async(req, res)=>{
const person = req.params.id;
const reqUrl = TigerGraphCred.queryUrl + `RP_getProfile?person=${person}`;
const response = await fetch(reqUrl, {
headers:{
"Content-Type": "application/json",
"Authorization": `Bearer ${TigerGraphCred.token}`,
"Accept":"application/json"
}
});
if(response.status === 200){
const json = await response.json();
//query for the error and send appropriate status code and response
if(json.error){
res.status(400).send({"error": json.message});
}
else{
res.status(200).send(json);
}
}
else{
const message = await response.text();
res.status(500).send({'error': message});
}
});
app.listen(5000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment