Skip to content

MuslimShah/JobsAPI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JobsAPI

JobsAPI is a Node.js API that allows users to register, create, update, and delete jobs.

Author

Muslim Shah

Date

May 25, 2023

Cloning the Repository

To clone the JobsAPI project, follow these steps:

	git clone [email protected]:MuslimShah/JobsAPI.git

Installation

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

Configuration

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.

Starting the API

Once the installation and configuration are complete, you can start the API by running:

	npm start

API Routes

/api/v1/auth

  • POST /register
  • POST /login

/api/v1/jobs (Authentication required)

  • 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)

Create Job Request

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"
}
	

Register User Request

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"
}

Login Request

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"
}

Responses

  • 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" }

    Security Packages

    • 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.

    Error Handling

    • express-async-errors: Handles asynchronous errors in Express middleware and routes.

    Database

    • 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.

    Use My Deployed version

    URL

    https://nice-lime-cockatoo-wig.cyclic.app

    Just include before your endpoint

    Example:

    https://nice-lime-cockatoo-wig.cyclic.app/api/v1/jobs

About

small jobs api followed from udemy course

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published