This is a simple CRUD (Create, Read, Update, Delete) RESTful API built using Node.js and Express.js. The API allows users to manage orders and products, as well as perform user authentication and authorization.
- User can create an account and log in
- User can create, read, update, and delete orders and products via RESTful API
- User can upload files (images, documents, etc.) using Multer
- Secure user authentication and password hashing using bcrypt
- Uses Mongoose for MongoDB integration
- Node.js
- Express.js
- MongoDB
- Mongoose
- Multer
- bcrypt
- jsonwebtoken
- Clone the repository:
git clone https://github.com/MdShimulMahmud/RESTful-API.git
- Install dependencies:
cd RESTful-API
npm install
- Create a
.env
file and add your MongoDB Atlas connection string and session secret:
MONGO_PASSWORD=<your-mongodb-atlas-uri>
JWT_KEY=<your-secret-key>
- Start the application:
npm start
Postman
POST /api/users/signup
: Creates a new user account. Expects a JSON body withemail
andpassword
fields.POST /api/users/login
: Authenticates a user. Expects a JSON body withemail
andpassword
fields.
GET /api/products
: Returns a list of all products.GET /api/products/:id
: Returns the product with the specified ID.POST /api/products
: Creates a new product. Expects a JSON body withname
,price
, andfile
fields (for file upload).PUT /api/products/:id
: Updates the product with the specified ID. Expects a JSON body withname
andprice
fields (for non-file updates).DELETE /api/products/:id
: Deletes the product with the specified ID.
GET /api/orders
: Returns a list of all orders.GET /api/orders/:id
: Returns the order with the specified ID.POST /api/orders
: Creates a new order. Expects a JSON body withproductId
andquantity
fields.PUT /api/orders/:id
: Updates the order with the specified ID. Expects a JSON body withproductId
andquantity
fields.DELETE /api/orders/:id
: Deletes the order with the specified ID.
To upload files, send a multipart/form-data
request with a file
field containing the file to be uploaded.
This API uses bcrypt for password hashing and verification to ensure secure authentication. Please make sure to set a strong JWT_KEY in your .env
file to further enhance security.