Skip to content

Commit

Permalink
feat: add endpoint for getting a json from id
Browse files Browse the repository at this point in the history
  • Loading branch information
gjgd committed Oct 10, 2020
1 parent ec1327d commit 322c12d
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions packages/api/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,22 @@ app.get('/test', (req, res) => {
res.status(200).send('Request received');
});

app.get('/:id', async (req, res) => {
const { id } = req.params;
const params = {
TableName: process.env.TABLE_NAME,
Key: {
id,
},
};
const record = await dynamoDb.get(params).promise();
if (record.Item) {
res.status(200).send(record.Item.json);
} else {
res.sendStatus(404);
}
});

app.post('/', async (req, res) => {
const { body } = req;
const id = uuidv4();
Expand Down

0 comments on commit 322c12d

Please sign in to comment.