Giter Site home page Giter Site logo

myfirstapi's Introduction

MyFirstAPI

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.

Prerequisites

  1. Node.js and npm installed on your system
  2. MongoDB installed and running locally

Installation

  1. Clone the repository:

    git clone https://github.com/Houssem64/MyFirstApi.git
  2. Navigate to the project directory:

    cd MyFirstApi
  3. Install dependencies:

    npm install

Configuration

  1. Update the .env file with your MongoDB connection details:
    DATABASE_URL=mongodb://localhost:27017/subscriber

Running the API

Start the API server using the following command:

npm DevStart
or
Yarn DevStart

This will start the API server on port 3000.

API Endpoints

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

Example Usage

# 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

License

This project is licensed under the MIT License.

myfirstapi's People

Contributors

houssem64 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.