A simple user
CRUD api built using serverless framework and node.js to be deployed on AWS.
GET
/
None
http code content-type response 200 application/json list of apis
[{ "userAPIs":[ {"api":"Get user","route":"/users/:userId","method":"GET"}, {"api":"Create user","route":"/users","method":"POST"}, {"api":"Update user","route":"/users/:userId","method":"PUT"}, {"api":"Delete user","route":"/users/:userId","method":"DELETE"} ] }]
curl http://localhost:3000/users
POST
/users
name type data type description None required object/json request.body
{ "userId": (will be part of the response), "firstName": <required>, "lastName": <required>, "email": <required>, "dateOfBirth": [optional], "phone": [optional], "address": [optional], "city": [optional], "state": [optional], "country": [optional], "zipCode": [optional] }
http code content-type response 201 application/json user object 400 application/json {"code":"400","message":"Bad Request"}
curl -X POST -H "Content-Type: application/json" -d '{"firstName":"john","lastName":"doe","email":"[email protected]"}' http://localhost:3000/users
GET
/users/{userId}
name type data type description userId required string user id obtained via create user response
http code content-type response 200 application/json user object 404 application/json {"code":"404","message":"could not find user with provided userId"}
curl -X GET http://localhost:3000/users/a234-ty09-3395-39lk-309u
PUT
/users/{userId}
name type data type description userId required string user id obtained via create user response None required object/json request.body
http code content-type response 200 application/json user object 400 application/json {"code":"400","message":"Bad Request"} 404 application/json {"code":"404","message":"could not find user with provided userId"}
curl -X POST -H "Content-Type: application/json" -d '{"firstName":"john","lastName":"doe","email":"[email protected]"}' http://localhost:3000/users
DELETE
/users/{userId}
name type data type description userId required string user id obtained via create user response
http code content-type response 200 application/json empty object 404 application/json {"code":"404","message":"could not delete user with provided userId"}
curl -X DELETE http://localhost:3000/users/a234-ty09-3395-39lk-309u
- Node.js Version 18+
- npm (package manager)
- Mocha (to execute tests)
- Docker (to run local dynamodb)
- Serverless (install globally)
- Serverless subscription (for deployment, use free tier)
- AWS cli (for deployment)
- AWS account (for deployment)
Install dependencies by executing the following from the root of the repository,
$ npm i
Start the service by executing the following from the root of the repository,
$ npm run sls_offline_start_local
To execute unit tests, open another terminal session and execute the following from the root of the repository,
$ npm run test
Unit tests do not need the service in the background!
To execute functional tests, open another terminal session and execute the following from the root of the repository,
$ npm run ft_test
Execute the following from the root fo the repository.
Create a free subscription with serverless!
Login to serverless service (and follow the prompts, may need to enable/allow AWS integration if not already done),
$ sls login
To deploy (to AWS),
$ sls deploy
To remove deployment (remove the stack from AWS),
$ sls remove
- No security features are implemented, this is just a showcase of serverless api.
- Only
firstName
,lastName
,email
are required, other fields/attributes/properties are optional. userId
is the partition key and a global secondary index is set onemail
.email
should be unique, other fields are flexible and can have duplicates, again this is to showcase handling of unique fields.