This project is a RESTful API built with Express.js that allows for Create, Read, Update, and Delete (CRUD) operations on user data.
- Create a new user
- Retrieve details of an existing user
- Update information of an existing user
- Delete a user
-
Clone the repository:
git clone https://github.com/MrBalla/express-users-crud-rest-api.git
-
Navigate to the project directory:
cd express-users-crud-rest-api
-
Install the dependencies:
npm install
-
Start the server:
npm start
By default, the server will run on
http://localhost:3000. -
API Endpoints:
-
Create a new user
- URL:
POST /users - Body Parameters:
name(string): The name of the user.email(string): The email address of the user.
- URL:
-
Retrieve a user by ID
- URL:
GET /users/:id - URL Parameters:
:id(integer): The unique identifier of the user.
- URL:
-
Update a user's information
- URL:
PUT /users/:id - URL Parameters:
:id(integer): The unique identifier of the user.
- Body Parameters:
name(string): The updated name of the user.email(string): The updated email address of the user.
- URL:
-
Delete a user
- URL:
DELETE /users/:id - URL Parameters:
:id(integer): The unique identifier of the user.
- URL:
-
To run the application using Docker:
-
Build the Docker image:
docker build -t express-users-crud-rest-api .
-
Run the Docker container:
docker run -p 3000:3000 express-users-crud-rest-api
The API will be accessible at
http://localhost:3000.
-
Install Swagger dependencies:
npm install swagger-jsdoc swagger-ui-express
-
Configure Swagger in your app:
const swaggerJsDoc = require('swagger-jsdoc'); const swaggerUi = require('swagger-ui-express'); const swaggerOptions = { swaggerDefinition: { openapi: '3.0.0', info: { title: 'Express Users CRUD API', version: '1.0.0', description: 'A simple Express CRUD API' } }, apis: ['./routes/*.js'] }; const swaggerDocs = swaggerJsDoc(swaggerOptions); app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocs));
Visit
http://localhost:3000/api-docsto see your API documentation.
-
Install nodemon:
npm install --save-dev nodemon
-
Update your
package.json:"scripts": { "start": "nodemon index.js" }
Now your server will auto-reload on code changes.
This project is licensed under the MIT License. See the LICENSE file for details.