This API provides a backend service for managing table reservations for a restaurant. It allows authorized restaurant staff to create, view, update, and manage table reservations efficiently. The API is built using Node.js, Express.js, and MongoDB, and incorporates Google Authentication for secure access.
- Table Management:
- Create, retrieve, update, and delete restaurant tables.
- Reservation Management:
- Create, retrieve, update, and delete table reservations.
- Update reservation status (e.g., Pending, Confirmed, Seated, Cancelled).
- User Authentication:
- Secure login using Google Authentication via OAuth 2.0.
- Protected API routes requiring authentication for access.
- Restaurant Information Management:
- Retrieve and update general restaurant information (name, address, phone, etc.).
- Data Validation:
- Robust data validation on all API endpoints to ensure data integrity.
- Clear error responses for invalid requests.
- Error Handling:
- Comprehensive error handling throughout the API for consistent and informative responses.
- API Documentation:
- Interactive API documentation generated using Swagger/OpenAPI, available at
/api-docsendpoint.
- Interactive API documentation generated using Swagger/OpenAPI, available at
- Backend:
- Node.js - JavaScript runtime environment
- Express.js - Web application framework for Node.js
- Database:
- Authentication:
- Passport.js - Authentication middleware for Node.js
- passport-google-oauth20 - Passport strategy for Google OAuth 2.0
- express-session - Middleware for session management
- Data Validation:
- Joi - JavaScript object schema validation
- API Documentation:
- Swagger-jsdoc - OpenAPI/Swagger specification generator
- Swagger-ui-express - Serve Swagger UI for Express.js
- Templating Engine (Frontend - Optional):
- EJS - Embedded JavaScript templates (for basic frontend, if implemented)
- Environment Variables:
- dotenv - Load environment variables from
.envfile
- dotenv - Load environment variables from
These instructions will guide you on how to set up and run the Restaurant Reservation API on your local machine for development and testing.
- Node.js (version 18 or later recommended)
- npm (Node Package Manager, usually comes with Node.js)
- MongoDB - Ensure MongoDB is installed and running locally or you have access to a MongoDB Atlas cluster.
-
Clone the repository:
git clone [YOUR_REPOSITORY_URL] # Replace with your repository URL cd restaurant-reservation-api
-
Install npm dependencies:
npm install
-
Set up Environment Variables:
-
Create a
.envfile in the root of your project directory. -
Add the following environment variables to your
.envfile, replacing the placeholder values with your actual credentials:MONGODB_URI=mongodb://localhost:27017/restaurant_reservation_db # Or your MongoDB Atlas connection string GOOGLE_CLIENT_ID=<YOUR_GOOGLE_CLIENT_ID> GOOGLE_CLIENT_SECRET=<YOUR_GOOGLE_CLIENT_SECRET> GOOGLE_CALLBACK_URL=http://localhost:3000/auth/google/callback SESSION_SECRET=<YOUR_STRONG_SESSION_SECRET> # Generate a strong secret! PORT=3000 # Optional: Customize the port
Important:
- Obtain your
GOOGLE_CLIENT_IDandGOOGLE_CLIENT_SECRETfrom the Google Cloud Console. - Set up your "Authorized redirect URIs" in Google Cloud Console to
http://localhost:3000/auth/google/callback(for local development). - Replace
<YOUR_STRONG_SESSION_SECRET>with a truly random and long string for session security (you can generate one using the provided script or online tools). - Adjust
MONGODB_URIto your MongoDB connection string (local or Atlas).
- Obtain your
-
node server.js