This repository uses Serverless Framework with AWS can supports offline mode to complete the solution at local environment.
- Use the 16.x version of NodeJS framework by NVM
nvm use 16
- Install Yarn
npm instal -g yarn typescript
- Install all node packages by yarn
yarn install
- Install serverless framework
npm install -g serverless
- Install dynamodb local for serverless
serverless dynamodb install
Caution: The dynamodb local requires the machine has been installed Java JRE > 8 to run
- Start the serverless offline by
serverless offline start
- There are two ways to execute the API:
- Import the postman configuration file to Postman and execute the collection API.
{
"info": {
"_postman_id": "9a30abb0-eff7-45d3-88ef-3913164c4768",
"name": "Earthquakes",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "FetchEarthquakes",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "http://localhost:3000/dev/earthquakes/fetch",
"protocol": "http",
"host": [
"localhost"
],
"port": "3000",
"path": [
"dev",
"earthquakes",
"fetch"
]
}
},
"response": []
},
{
"name": "GetEarthquakes",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "http://localhost:3000/dev/earthquakes",
"protocol": "http",
"host": [
"localhost"
],
"port": "3000",
"path": [
"dev",
"earthquakes"
],
"query": [
{
"key": "limit",
"value": "50",
"disabled": true
},
{
"key": "cursor",
"value": null,
"disabled": true
}
]
}
},
"response": []
},
{
"name": "GetRequestHistory",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "http://localhost:3000/dev/history",
"protocol": "http",
"host": [
"localhost"
],
"port": "3000",
"path": [
"dev",
"history"
],
"query": [
{
"key": "limit",
"value": "50",
"disabled": true
},
{
"key": "cursor",
"value": null,
"disabled": true
}
]
}
},
"response": []
}
]
}
- Uses CURL:
- Fetch earthquakes
curl --location --request GET 'http://localhost:3000/dev/earthquakes/fetch'
- Get earthquakes (Can add optional parameters:
limit
andcursor
).Cursor
is thecode
(this is primary key)
curl --location --request GET 'http://localhost:3000/dev/earthquakes'
- Get request history (Can add optional parameters:
limit
andcursor
).Cursor
is therequestId
(this is primary key)
curl --location --request GET 'http://localhost:3000/dev/history'