Skip to content

Commit

Permalink
feat: add endpoint to save a json under a uuid
Browse files Browse the repository at this point in the history
  • Loading branch information
gjgd committed Oct 10, 2020
1 parent 536e3a9 commit 1ca83f4
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
20 changes: 20 additions & 0 deletions packages/api/app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
const express = require('express');
const { DynamoDB } = require('aws-sdk');
const { v4: uuidv4 } = require('uuid');

const app = express();
const dynamoDb = new DynamoDB.DocumentClient();

// Enable CORS
// app.use((req, res, next) => {
Expand All @@ -19,6 +22,23 @@ app.get('/test', (req, res) => {
res.status(200).send('Request received');
});

app.post('/', async (req, res) => {
const { body } = req;
const { url } = body;
const id = uuidv4();
const params = {
TableName: process.env.TABLE_NAME,
Item: {
id,
url,
created_timestamp: Date.now(),
created_date: new Date().toISOString(),
},
};
await dynamoDb.put(params).promise();
res.status(200).send(`api.jsonld-checker.com/${id}`);
});

app.get('/*', (req, res) => {
res.status(404).send('Route not found');
});
Expand Down
13 changes: 10 additions & 3 deletions packages/api/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
},
"dependencies": {
"aws-sdk": "^2.701.0",
"express": "^4.17.1"
"express": "^4.17.1",
"uuid": "^8.3.1"
}
}
3 changes: 3 additions & 0 deletions packages/api/serverless.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: jsonld-checker-api
app: jsonld-checker
component: express
org: gjgdserverless
repo: https://github.com/gjgd/jsonld-checker
Expand All @@ -7,3 +8,5 @@ license: MIT
inputs:
src: ./
domain: api.jsonld-checker.com
env:
TABLE_NAME: ${output:jsonld-checker-db.name}

0 comments on commit 1ca83f4

Please sign in to comment.