A RESTful API backend built with Express.js and Mongoose for managing messages with full CRUD operations.
- ✅ Complete CRUD operations for messages
- ✅ Standardized JSON response format
- ✅ MongoDB integration with Mongoose
- ✅ Error handling middleware
- ✅ Environment configuration
- ✅ Postman/Thunder Client collection for testing
- ✅ Controller-based architecture
Backend Example/
├── controllers/
│ └── messageController.js # Business logic for message operations
├── models/
│ └── Message.js # Mongoose schema for messages
├── routes/
│ └── messageRoutes.js # API route definitions
├── tests/
│ ├── Backend_Example_API.postman_collection.json
│ └── README.md # Testing instructions
├── .env # Environment variables
├── package.json # Dependencies and scripts
└── server.js # Main server file
npm installMake sure MongoDB is running locally, or update the .env file with your MongoDB connection string.
# Development mode with auto-restart
npm run dev
# Production mode
npm startThe server will start on http://localhost:3000
All responses follow the standardized format:
Success Response:
{
"success": true,
"data": { ... }
}Error Response:
{
"success": false,
"error": "Descriptive error message"
}| Method | Endpoint | Description |
|---|---|---|
| POST | /api/messages |
Create a new message |
| GET | /api/messages |
Get all messages |
| GET | /api/messages/:id |
Get a specific message by ID |
| PUT | /api/messages/:id |
Update a message by ID |
| DELETE | /api/messages/:id |
Delete a message by ID |
{
"author": "string (required, max 100 chars)",
"text": "string (required, max 1000 chars)",
"timestamp": "Date (auto-generated)",
"isRead": "boolean (default: false)"
}- Import the collection:
tests/Backend_Example_API.postman_collection.json - Test each endpoint with the provided sample data
- Install Thunder Client extension
- Follow the instructions in
tests/README.md
Create a message:
curl -X POST http://localhost:3000/api/messages \
-H "Content-Type: application/json" \
-d '{
"author": "John Doe",
"text": "Hello, this is a test message!",
"isRead": false
}'Get all messages:
curl http://localhost:3000/api/messagesGet message by ID:
curl http://localhost:3000/api/messages/msg-001Update a message:
curl -X PUT http://localhost:3000/api/messages/msg-001 \
-H "Content-Type: application/json" \
-d '{
"author": "Jane Doe",
"text": "Updated message text",
"isRead": true
}'Delete a message:
curl -X DELETE http://localhost:3000/api/messages/msg-001Phase 1: ✅ Complete
- Routes & Endpoints (all 5 CRUD operations)
- Controller placeholders with standardized responses
- Shared response format implementation
- Testing setup (Postman & Thunder Client collections)
Phase 2: 🔄 Ready for Implementation
- Replace placeholder responses with actual database operations
- Add data validation
- Implement error handling for edge cases
- Add authentication (optional)
The current implementation uses placeholder responses. To connect to the database:
- Uncomment the database logic in
controllers/messageController.js - Replace placeholder responses with actual Mongoose operations
- Test with real data
PORT=3000
MONGODB_URI=mongodb://localhost:27017/backend-exampleFor production, replace MONGODB_URI with your actual MongoDB connection string.
- express: Web framework
- mongoose: MongoDB object modeling
- cors: Cross-origin resource sharing
- dotenv: Environment variable management
- nodemon: Development auto-restart (dev dependency)