This repository contains a simple REST API built with Express, a popular web framework for Node.js. The API allows users to perform basic CRUD (create, read, update, delete) operations on a resource representing a user. It includes support for HTTP requests, route handling, and input validation.
- Endpoints for managing users:
- GET /users: retrieves a list of all users
- GET /users/:id: retrieves a specific user by ID
- POST /users: creates a new user
- PUT /users/:id: updates an existing user
- DELETE /users/:id: deletes a user
- Validates user input to ensure that required fields are present
- Uses cors to allow cross-origin requests
- Uses dotenv to load environment variables from a .env file
- Node.js
- npm (should be installed with Node.js)
- Clone or download this repository
- Navigate to the root directory of the project
- Install dependencies by running npm install
- Create a .env file in the root directory and set the PORT environment variable (e.g. PORT=3001)
- Start the API by running npm start
You can use the following examples to interact with the API using [cURL|https://curl.haxx.se/]:
curl -X GET http://localhost:3001/users
curl -X GET http://localhost:3001/users/1
curl -X POST -H "Content-Type: application/json" -d '{
"name": {
"first": "Jane",
"last": "Doe"
},
"email": "jane.doe@example.com",
"password": "123456"
}' http://localhost:3001/users
curl -X PUT -H "Content-Type: application/json" -d '{
"name": {
"first": "John",
"last": "Smith"
},
"email": "john.smith@example.com"
}' http://localhost:3001/users/1
curl -X DELETE http://localhost:3001/users/1