Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vinodchauhan7/844f081631ef009ef236c31c5bff128e to your computer and use it in GitHub Desktop.
Save vinodchauhan7/844f081631ef009ef236c31c5bff128e to your computer and use it in GitHub Desktop.
/getUser/:id
router.get("/getUser/:id",(context : any) => {
try{
const decoder = new TextDecoder("utf-8");
const data = Deno.readFileSync("./users.json");
console.log(decoder.decode(data));
const users = JSON.parse(decoder.decode(data));
if (context.params && context.params.id && users["user"+context.params.id])
{
const user = users["user"+context.params.id];
context.response.body = user;
}
else{
context.response.status = 404;
context.response.body = `User with id ${context.params.id} does not exist`;
}
}
catch(err){
console.log(err);
context.response.status = 500;
context.response.body = err;
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment