Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save azizkale/e7a32bf99a8da8b84921e64db453d8f9 to your computer and use it in GitHub Desktop.
Save azizkale/e7a32bf99a8da8b84921e64db453d8f9 to your computer and use it in GitHub Desktop.
/**
* @swagger
* /posts/{id}:
* get:
* summary: gets posts by id
* tags: [Posts]
* parameters:
* - in : path
* name: id
* description: id of post
* schema:
* type: integer
* required: true
* responses:
* 200:
* description: posts by its id
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/Post'
* 400:
* description: post can not be found
*/
postRouter.get("/:id", (req, res) => {
const post = data.find((post) => post.id === +req.params.id);
if (!post) {
res.sendStatus(404);
}
res.send(post);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment