In this tutorial, I demonstrate a fully functional REST API built with Node.js, Express, MongoDB, and Google OAuth authentication. This API supports full CRUD operations, data validation, error handling, and automatic API documentation with Swagger.
🚀 Live Demo
🔗 *Render URL:* https://w03-crud-api-1.onrender.com
📂 GitHub Repository
🐙 *Source Code:* https://github.com/Benjaminsoosay/w03-crud...
✨ Features Demonstrated
✅ *Google OAuth Authentication* - Secure login with Google accounts
✅ *Full CRUD Operations* - Create, Read, Update, Delete for Items & Categories
✅ *Data Validation* - Proper 400 error responses for invalid data
✅ *Error Handling* - Try-catch blocks with appropriate status codes
✅ *Swagger Documentation* - Auto-generated, interactive API docs
✅ *MongoDB Database* - Cloud-hosted with 7+ fields per document
✅ *Protected Routes* - POST, PUT, DELETE require authentication
✅ *Public Routes* - GET endpoints accessible without login
🛠️ Tech Stack
*Backend:* Node.js, Express.js
*Database:* MongoDB Atlas
*Authentication:* Passport.js with Google OAuth 2.0
*Documentation:* Swagger UI / OpenAPI 3.0
*Deployment:* Render.com
*Version Control:* Git & GitHub
📊 API Endpoints
Public Routes (No Login Required)
`GET /` - API status
`GET /items` - Get all items
`GET /items/{id}` - Get single item
`GET /categories` - Get all categories
`GET /categories/{id}` - Get single category
Protected Routes (Google Login Required)
`POST /items` - Create new item
`PUT /items/{id}` - Update item
`DELETE /items/{id}` - Delete item
`POST /categories` - Create category
`PUT /categories/{id}` - Update category
`DELETE /categories/{id}` - Delete category
Authentication Endpoints
`GET /auth/google` - Login with Google
`GET /logout` - Logout user
`GET /auth/status` - Check authentication status
🎯 Rubric Requirements Met
✅ Two collections (Items & Categories)
✅ 7+ fields in Items collection
✅ Full CRUD operations
✅ Data validation (400 errors)
✅ Error handling (try/catch)
✅ OAuth authentication (Google)
✅ Deployed to Render
✅ Swagger documentation
📝 How to Use
1. Visit the Swagger UI: `https://w03-crud-api-1.onrender.com/api-docs`
2. Click "Authorize" and log in with Google
3. Test any protected endpoint (POST, PUT, DELETE)
4. View data in MongoDB Compass
🔗 Links
*Live API:* https://w03-crud-api-1.onrender.com
*GitHub:* https://github.com/Benjaminsoosay/w03-crud...
*Swagger Docs:* https://w03-crud-api-1.onrender.com/api-docs
📧 Contact
*GitHub:* @Benjaminsoosay
*Project:* Week 4 Project - Authentication & CRUD API
👍 Like & Subscribe
If this tutorial helped you, please LIKE, SHARE, and SUBSCRIBE for more web development content!
#NodeJS #MongoDB #RESTAPI #OAuth #GoogleAuth #Swagger #WebDevelopment #CRUD #API