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.
-
Serverless REST API using AWS Lambda and API Gateway
-
Local simulation via serverless-offline
-
CRUD endpoints:
GET /user/{id}β Fetch a userPOST /userβ Create a new userPUT /user/{id}β Update an existing userDELETE /user/{id}β Remove a user
-
Uses
json-serveras a mock backend for local development -
Clean, extensible structure for cloud or local use
- Node.js 18+
- Serverless Framework
- AWS Lambda (simulated locally)
- json-server
- Axios
git clone https://github.com/<your-username>/<repo-name>.git
cd <repo-name>npm installRun a local JSON server:
npx json-server --watch db.json --port 8080npx serverless offlineAPI base URL:
http://localhost:3000
Fetch a user by ID.
curl http://localhost:3000/user/1Response
{
"message": "User fetched successfully!",
"data": {
"id": 1,
"name": "John Doe"
}
}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"
}
}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 a user by ID.
curl -X DELETE http://localhost:3000/user/1Response
{
"message": "User deleted successfully!"
}.
βββ 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
- 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
Gurunatharudh Bhandarkavathe Node.js Developer | Serverless Enthusiast