Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🧩 Serverless REST API (Node.js + AWS Lambda + Local Simulation)

This project demonstrates a Serverless REST API built using Node.js, AWS Lambda, and the Serverless Framework, with local simulation using serverless-offline. It integrates with a local json-server to perform full CRUD operations on user data.


πŸš€ Features

  • Serverless REST API using AWS Lambda and API Gateway

  • Local simulation via serverless-offline

  • CRUD endpoints:

    • GET /user/{id} β†’ Fetch a user
    • POST /user β†’ Create a new user
    • PUT /user/{id} β†’ Update an existing user
    • DELETE /user/{id} β†’ Remove a user
  • Uses json-server as a mock backend for local development

  • Clean, extensible structure for cloud or local use


πŸ› οΈ Tech Stack

  • Node.js 18+
  • Serverless Framework
  • AWS Lambda (simulated locally)
  • json-server
  • Axios

βš™οΈ Setup Instructions

1. Clone the repo

git clone https://github.com/<your-username>/<repo-name>.git
cd <repo-name>

2. Install dependencies

npm install

3. Start mock database

Run a local JSON server:

npx json-server --watch db.json --port 8080

4. Start Serverless Offline

npx serverless offline

API base URL:

http://localhost:3000

πŸ“‘ API Endpoints

🟒 GET /user/{id}

Fetch a user by ID.

curl http://localhost:3000/user/1

Response

{
  "message": "User fetched successfully!",
  "data": {
    "id": 1,
    "name": "John Doe"
  }
}

🟣 POST /user

Create a new user.

curl -X POST http://localhost:3000/user \
  -H "Content-Type: application/json" \
  -d '{"name": "Alice"}'

Response

{
  "message": "User created successfully!",
  "data": {
    "id": 4,
    "name": "Alice"
  }
}

🟠 PUT /user/{id}

Update an existing user.

curl -X PUT http://localhost:3000/user/1 \
  -H "Content-Type: application/json" \
  -d '{"name": "Updated Name"}'

Response

{
  "message": "User updated successfully!",
  "data": {
    "id": 1,
    "name": "Updated Name"
  }
}

πŸ”΄ DELETE /user/{id}

Delete a user by ID.

curl -X DELETE http://localhost:3000/user/1

Response

{
  "message": "User deleted successfully!"
}

πŸ“ Project Structure

.
β”œβ”€β”€ handler.js              # Lambda handlers for CRUD operations
β”œβ”€β”€ serverless.yml          # Serverless Framework configuration
β”œβ”€β”€ package.json            # Dependencies and scripts
β”œβ”€β”€ db.json                 # JSON Server data file
└── README.md

πŸ”§ Future Enhancements

  • Add centralized error handling and validation
  • Integrate with real AWS DynamoDB or OpenSearch
  • Add unit tests using Jest
  • Enable deployment to AWS Lambda and API Gateway

πŸ§‘β€πŸ’» Author

Gurunatharudh Bhandarkavathe Node.js Developer | Serverless Enthusiast


About

A serverless REST API built with Node.js, AWS Lambda, and Serverless Framework, featuring full CRUD operations with local simulation using serverless-offline and json-server.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages