Skip to content

This is an API management system whereby Individuals can view and manage their respective cars

Notifications You must be signed in to change notification settings

Developer-Kings-dev/Creserver

Repository files navigation

Owner and Car Management API

This project is a backend API for managing car owners and their vehicles. It is built using Node.js, Express, and MongoDB and follows a RESTful API design pattern. The API supports essential CRUD operations for owners and cars, along with secure authentication using JWT.

Features

Owner Management: Create, update, view, and delete owner records.
Car Management: Add new cars, view car details, update car information, and remove cars.
Authentication: Login functionality using JWT for secure access.
Error Handling: Handles errors gracefully with custom error messages.
RESTful API: Clean and structured endpoint design.

Technology Stack

Node.js: Backend runtime environment.
Express: Web framework for building API endpoints.
MongoDB: NoSQL database for persisting owner and car data.
JWT (jsonwebtoken): Authentication and secure access.
Mongoose: MongoDB object modeling for Node.js.
Bcrypt: For securely hashing passwords.

API Endpoints

Owner Endpoints
POST /owners - Create a new owner.
POST /owners/login - Login an owner and generate a JWT token.
GET /owners - Retrieve all owners.
GET /owners/detail - Retrieve detailed information about a specific owner.
PUT /owners/{ownerId} - Fully update an owner's details.
PATCH /owners/{ownerId} - Partially update an owner's details.
DELETE /owners/{ownerId} - Delete an owner.

Car Endpoints
POST /cars - Create a new car.
GET /cars - Retrieve all cars.
GET /cars/{carId} - Retrieve a specific car's details.
PUT /cars/{carId} - Update car information.
DELETE /cars/{carId} - Delete a car.

Setup and Usage

Clone the repository:

bash or terminal
Copy code
git clone https://github.com/yourusername/yourprojectname.git

Install dependencies:
bash or terminal
Copy code;
npm install

Create a .env file in the root directory and configure the following environment variables:
Add the variables below to .env file;
DB_URI=mongodb://localhost:27017/techyjauntcars
PORT=4500
JWT_SECRET=your_jwt_secret_here

Run the server:

bash or teminal
Copy code
npm start
The API will now be available at http://localhost:4500.

Dependencies

express: Web framework for Node.js.
jsonwebtoken: For generating and verifying JWTs.
mongoose: MongoDB object modeling.
bcrypt: For password hashing and salting.
dotenv: Loads environment variables from a .env file.
body-parser: Middleware for parsing request bodies.
express-async-handler: Simplifies error handling for async functions.

API Testing with Insomnia

To test the API, you can import the provided Insomnia workspace and test the endpoints directly.
Download the insomnia/api-requests.json file from this repository.
Open Insomnia and go to Application Menu > Import/Export > Import Data.
Select the downloaded api-requests.json file to load the API requests for this project.

License

This project is licensed under the MIT License.

About

This is an API management system whereby Individuals can view and manage their respective cars

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published