Git Product home page Git Product logo

aws-node-express-dynamo-api's Introduction

Serverless Node Express API on AWS

A simple user CRUD api built using serverless framework and node.js to be deployed on AWS.

API endpoints

List APIs

GET /
Parameters

None

Response
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"}
      ]
  }]
Example cURL
 curl http://localhost:3000/users

Create User

POST /users
Parameters
name type data type description
None required object/json request.body
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]
 }
Responses
http code content-type response
201 application/json user object
400 application/json {"code":"400","message":"Bad Request"}
Example cURL
 curl -X POST -H "Content-Type: application/json" -d '{"firstName":"john","lastName":"doe","email":"[email protected]"}' http://localhost:3000/users

Get User

GET /users/{userId}
Parameters
name type data type description
userId required string user id obtained via create user response
Responses
http code content-type response
200 application/json user object
404 application/json {"code":"404","message":"could not find user with provided userId"}
Example cURL
 curl -X GET http://localhost:3000/users/a234-ty09-3395-39lk-309u

Update User

PUT /users/{userId}
Parameters
name type data type description
userId required string user id obtained via create user response
None required object/json request.body
Responses
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"}
Example cURL
 curl -X POST -H "Content-Type: application/json" -d '{"firstName":"john","lastName":"doe","email":"[email protected]"}' http://localhost:3000/users

Delete User

DELETE /users/{userId}
Parameters
name type data type description
userId required string user id obtained via create user response
Responses
http code content-type response
200 application/json empty object
404 application/json {"code":"404","message":"could not delete user with provided userId"}
Example cURL
 curl -X DELETE http://localhost:3000/users/a234-ty09-3395-39lk-309u

Local setup

Requirements

  • 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

Install dependencies by executing the following from the root of the repository,

$ npm i

Tests

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

Deployment

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

Notes

  • 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 on email.
  • email should be unique, other fields are flexible and can have duplicates, again this is to showcase handling of unique fields.

aws-node-express-dynamo-api's People

Contributors

naren-rajendran avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.