JobsAPI is a Node.js API that allows users to register, create, update, and delete jobs.
Muslim Shah
May 25, 2023
To clone the JobsAPI project, follow these steps:
git clone [email protected]:MuslimShah/JobsAPI.git
Before running the API, make sure you have the following dependencies installed:
- Node.js
- npm (Node Package Manager)
- MongoDB
After cloning the repository, navigate to the project directory and install the required dependencies:
npm install
Make sure to set up the following environment variables:
- PORT: The port on which the API will run
- MONGODB_URI: The connection URI for MongoDB
You can create a .env
file in the project root directory and set the environment variables there.
Once the installation and configuration are complete, you can start the API by running:
npm start
- POST /register
- POST /login
- GET / (Get all jobs created by the user)
- POST / (Create a new job)
- GET /:id (Get a single job by ID)
- PATCH /:id (Update a job by ID)
- DELETE /:id (Delete a job by ID)
To create a new job, send a POST request to the following endpoint:
POST /api/v1/jobs
The request body should contain the following data:
- company (string): The name of the company.
- position (string): The position of the job (e.g., intern, engineer, manager).
Example request body:
{
"company": "google",
"position": "intern"
}
To register a new user, send a POST request to the following endpoint:
POST /api/v1/auth/register
The request body should contain the following data:
- name (string): The name of the user.
- email (string): The email address of the user.
- password (string): The password for the user's account.
Example request body:
{
"name": "John Doe",
"email": "[email protected]",
"password": "password123"
}
To authenticate a user and obtain a token, send a POST request to the following endpoint:
POST /api/v1/auth/login
The request body should contain the following data:
- email (string): The email address of the user.
- password (string): The password for the user's account.
Example request body:
{
"email": "[email protected]",
"password": "password123"
}
- Register Response:
- Status: 201
- Body: { user: { name: user.name }, token }
- Login Response:
- Status: 200
- Body: { user: { name: user.name }, token }
- Get All Jobs Response:
- Status: 200
- Body: { jobs: allJobs, count: allJobs.length }
- Get Single Job Response:
- Status: 200
- Body: singleJob
- Create Job Response:
- Status: 201
- Body: { job, msg: "Job created successfully" }
- Update Job Response:
- Status: 200
- Body: { job, msg: "Job updated successfully" }
- Delete Job Response:
- Status: 200
- Body: { msg: "Job deleted successfully" }
- helmet: Provides various security-related HTTP headers.
- cors: Enables Cross-Origin Resource Sharing (CORS) for handling requests from different domains.
- xss-clean: Prevents Cross-Site Scripting (XSS) attacks by sanitizing user input.
- express-limiter: Implements rate limiting to protect against brute force and denial-of-service attacks.
- express-async-errors: Handles asynchronous errors in Express middleware and routes.
- MongoDB: A NoSQL database for storing user and job data.
- Mongoose: An Object Data Modeling (ODM) library for MongoDB to provide a more intuitive interface for interacting with the database.
https://nice-lime-cockatoo-wig.cyclic.app
Just include before your endpoint
https://nice-lime-cockatoo-wig.cyclic.app/api/v1/jobs