Car Dealership API with JWT Authentication The Car Dealership API allows you to manage car dealerships, cars, and deals. It provides various endpoints for both users and dealers to view cars, deals, and perform buying/selling actions. The API uses the Express framework for handling HTTP requests and responses and utilizes the Faker.js library to generate sample data.
Installation Clone the repository: bash Copy code git clone https://github.com/your-username/car-dealership-api.git cd car-dealership-api Install dependencies: bash Copy code npm install Set Environment Variables: Create a .env file in the root directory and add the following:
makefile Copy code PORT=5000 SECRET_KEY=your_secret_key Replace your_secret_key with your desired secret key for JWT authentication.
Run the server: bash Copy code npm start The server will run on http://localhost:5000 by default.
Endpoints Authentication User Sign Up Endpoint: POST /signup Description: Creates a new user account with the provided credentials. Request Body: json Copy code { "name": "John Doe", "email": "[email protected]", "password": "password" } User Sign In Endpoint: POST /signin Description: Authenticates the user and generates a JWT token. Request Body: json Copy code { "email": "[email protected]", "password": "password" } User Sign Out Endpoint: POST /signout Description: Signs out the user by clearing JWT token. Protected Endpoints (Require Authentication) For protected endpoints, the client must include the JWT token in the Authorization header.
View All Cars Endpoint: GET /api/cars Description: Retrieves a list of all available cars. View Cars in a Dealership Endpoint: GET /api/cars/dealerships/:dealership Description: Retrieves a list of cars available in a specific dealership. View Deals from a Certain Dealership Endpoint: GET /api/dealerships/:dealership/deals Description: Retrieves a list of deals provided by a certain dealership. Buy a Car After a Deal Is Made Endpoint: POST /api/buy/:dealId Description: Allows the user to buy a car after a deal is made. Sample Data The API generates sample car-related data using Faker.js for demonstration purposes. The sample data includes information about cars, deals, and sold vehicles.
Authentication Flow The user signs up with their name, email, and password. The user signs in with their registered email and password. Upon successful authentication, the server generates a JWT token and sends it back to the client. The client includes the JWT token in the Authorization header for subsequent requests to protected endpoints. When the user signs out, the server clears the JWT token from the client-side. Please note that this is a sample README file, and you should customize it to fit your specific project, including adding detailed instructions, usage examples, deployment details, and any other relevant information. Additionally, make sure to implement appropriate error handling and security measures to ensure the safety and integrity of user data.