This project is a simple REST API built with Express that allows manipulation of a user list. It supports CRUD operations (Create, Read, Update, Delete) and includes middlewares to process requests in JSON format.
The API offers the following routes:
Returns a welcome message.
- URL:
/ - Method:
GET - Response:
<h1>Working with Express server.</h1>
Returns the list of users.
- URL:
/users - Method:
GET - Response:
[ { "id": 1, "name": "Jonathan Roberto", "age": 29 }, { "id": 2, "name": "Daniele Pavesi", "age": 31 } ]
Returns a specific user by ID.
- URL:
/users/:userId - Method:
GET - Parameters:
userId: The ID of the user to retrieve.
- Response:
{ "id": 1, "name": "Jonathan Roberto", "age": 29 }
Adds a new user to the list.
- URL:
/users - Method:
POST - Body:
{ "id": 3, "name": "New User", "age": 25 } - Response:
- Status code:
201 Created - Response body:
{ "id": 3, "name": "New User", "age": 25 }
- Status code:
Updates a specific user by ID.
- URL:
/users/:userId - Method:
PUT - Parameters:
userId: The ID of the user to update.
- Body:
{ "id": 1, "name": "Jonathan Updated", "age": 30 } - Response:
{ "id": 1, "name": "Jonathan Updated", "age": 30 }
Removes a specific user by ID.
- URL:
/users/:userId - Method:
DELETE - Parameters:
userId: The ID of the user to delete.
- Response:
- Status code:
204 No Content
- Status code:
You need to have Node.js and npm installed on your machine.
-
Clone the repository:
git clone <REPO_URL>
-
Navigate to the project directory:
cd API-REST -
Install the dependencies:
npm install
-
Start the server:
npm start
-
The server will be running at:
http://localhost:8080
- express: A web framework for Node.js.
- http-status-codes: A library for HTTP status codes.
If you need to install the dependencies manually, run the following commands:
npm install express
npm install http-status-codesIf you want to contribute to this project, follow these steps:
- Fork this repository.
- Create a new branch:
git checkout -b feature/MyNewFeature
- Make your changes and commit:
git commit -m "Added my new feature" - Push your changes:
git push origin feature/MyNewFeature
- Open a Pull Request.
This project is licensed under the MIT License. For more details, refer to the LICENSE file.