This is a simple project that I developed entirely on my own while studying REST APIs. I created an API for an online menu application, managing everything from user login to product listings.
- Features
- Tech Stack
- Installation
- Environment Variables
- Build
- Docker
- Run
- API Endpoints
- Contributing
- License
- Acknowledgements
- User, Restaurant, and Product CRUD operations.
- Image uploading and storage on the server.
- Token management using JWT.
- Typescript
- Node.js
- Express
- Nodemon
- Multer
- JWT
- Zod
- Prisma OEM
- PostgreSQL
To install the necessary packages, clone the repository and run the following command in the terminal:
npm i
Create a .env file in the root directory of your project and add the following environment variables:
DATABASE_URL=postgresql://USER:PASSWORD@HOST:PORT/DATABASE
TOKEN_SECRET=your_jwt_secret
Refer to the .env.example file for a complete list of required environment variables.
You can run the application using the development script. However, since Node.js does not natively support TypeScript and ES modules, you should create a build to use it:
npm run build
To set up a Docker container with PostgreSQL, use the following command:
docker run -d --name NAME -p PORT:PORT -e POSTGRES_PASSWORD=PASSWORD postgres
Replace the uppercase placeholders with the appropriate values as specified in the DATABASE_URL in your .env file.
Once everything is set up, you can start the application with the following commands:
For development:
npm run dev
For production (after building):
npm run start
- POST /token: Creates a token for a user by validating their credentials (email and password).
- POST /user: Create a new user.
- PATCH /user: Update the user using their token to identify them.
- DELETE /user: Delete the user using their token to identify them.
- POST /restaurants: Create a new restaurant and link it to the user registered in the token.
- PATCH /restaurants/: Update a restaurant using the user ID linked to it in the token to identify it.
- DELETE /restaurants/: Delete a restaurant using the user ID linked to it in the token to identify it.
- GET /restaurants/:id: Get a restaurant by ID.
- POST /products: Create a new product and link it to the restaurant registered in the token.
- PATCH /products/:id: Update the product using the ID passed in the request body and the restaurant ID registered in the token to identify it.
- DELETE /products/:id: Delete the product using the ID passed in the request body and the restaurant ID registered in the token to identify it.
- GET /products/:id: List all the products from a restaurant (by their ID).
Contributions are welcome! Please fork the repository and use a feature branch. Pull requests are warmly welcome.
- Fork the repository.
- Create your feature branch (
git checkout -b feature/AmazingFeature
). - Commit your changes (
git commit -m 'Add some AmazingFeature'
). - Push to the branch (
git push origin feature/AmazingFeature
). - Open a Pull Request.
This project is licensed under the MIT License. See the LICENSE file for details.do
This project may not be perfect, but it was a significant challenge for me to create a complete API. I learned a lot during its development, and it provided a solid foundation for my future studies and projects.