Skip to content

dxtaner/CarBrandNodejsApi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cars Express MongoDB API

Prerequisites

  • Node.js installed on your machine.
  • A MongoDB Atlas account or a local MongoDB server.

Setup

  1. Clone the repository or download the code.

  2. Install the required dependencies by running the following command:

    npm install

  3. Open the `app.js` file and replace the `dbURL` variable with your MongoDB connection string. If you're using a local MongoDB server, the URL might look like `mongodb://localhost:27017/mydatabase`.

API Endpoints

The API provides the following endpoints for managing cars, users, and brands:

Car Endpoints

  • `GET /api/cars` - Get all cars.
  • `GET /api/cars/:id` - Get a car by ID.
  • `POST /api/cars` - Create a new car.

User Endpoints

  • `GET /api/users` - Get all users.
  • `GET /api/users/:id` - Get a user by ID.
  • `POST /api/users\register` - Create a new user.
  • `POST /api/users\login` - login a user.
  • `PUT /api/users/:id` - Update a user by ID.
  • `DELETE /api/users/:id` - Delete a user by ID.

Brand Endpoints

  • `GET /api/brands` - Get all brands.
  • `GET /api/brands/:id` - Get a brand by ID.
  • `POST /api/brands` - Create a new brand.
  • `PUT /api/brands/:id` - Update a brand by ID.
  • `DELETE /api/brands/:id` - Delete a brand by ID.

You can use tools like Postman or cURL to send requests to these endpoints and manage the data.

Make sure to handle errors and validations appropriately and provide proper error messages or responses to the API consumers.

That's it! You have successfully set up the Express MongoDB API server. You can now start using the API endpoints to manage cars, users, and brands in your MongoDB database.