A Simple RESTful API This project demonstrates a simple RESTful API built using Node.js, Express, and MongoDB (Mongoose) to manage subscribers. It provides CRUD (Create, Read, Update, Delete) operations for subscribers.
- Node.js and npm installed on your system
- MongoDB installed and running locally
-
Clone the repository:
git clone https://github.com/Houssem64/MyFirstApi.git
-
Navigate to the project directory:
cd MyFirstApi
-
Install dependencies:
npm install
- Update the
.env
file with your MongoDB connection details:DATABASE_URL=mongodb://localhost:27017/subscriber
Start the API server using the following command:
npm DevStart
or
Yarn DevStart
This will start the API server on port 3000.
Method | Endpoint | Description |
---|---|---|
GET | /subscribers | Retrieves all subscribers |
POST | /subscribers | Creates a new subscriber |
GET | /subscribers/:id | Retrieves a specific subscriber by ID |
PUT | /subscribers/:id | Updates an existing subscriber |
DELETE | /subscribers/:id | Deletes a specific subscriber by ID |
# Get all subscribers
curl -X GET http://localhost:3000/subscribers
# Create a new subscriber
curl -X POST http://localhost:3000/subscribers -H "Content-Type: application/json" -d '{ "name": "John Doe", "subscribedToChannel": "Tech News" }'
# Get a specific subscriber by ID
curl -X GET http://localhost:3000/subscribers/1
# Update an existing subscriber
curl -X PUT http://localhost:3000/subscribers/1 -H "Content-Type: application/json" -d '{ "name": "Jane Doe", "subscribedToChannel": "News Inc" }'
# Delete a specific subscriber by ID
curl -X DELETE http://localhost:3000/subscribers/1
This project is licensed under the MIT License.