Skip to content

bradtraversy/contact_keeper_api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Contact Keeper API

This is a Node/Express/MongoDB REST API for contacts that uses JWT authentication. All contact endpoints are protected and each registered user has their own contacts. This is used in my React course on Udemy. It is the API ONLY. The fullstack app can be found here

Getting Started

  Open the config/default.json file and add your mongoURI and your jwtSecret
  npm install
  npm run server # Runs on http://localhost:5000

API Usage & Endpoints

Register a User [POST /api/users]

  • Request: Add user and request JSON web token

    • Headers

      Content-type: application/json
      
    • Body

          {
            "name": "",
            "email": "",
            "password": ""
          }
      
  • Response: 200 (application/json)

    • Body

        {
          "token": ""
        }
      

Login with a User [POST /api/auth]

  • Request: Login with credentials to recieve a JSON web token

    • Headers

      Content-type: application/json
      
    • Body

          {
            "email": "",
            "password": ""
          }
      
  • Response: 200 (application/json)

    • Body

        {
          "token": ""
        }
      

Get Contacts [GET /api/contacts]

  • Request: Get all contacts of a specific user

    • Headers

      x-auth-token: YOURJWT
      
  • Response: 200 (application/json)

    • Body

        {
          "contacts": []
        }
      

Add New Contact [POST /api/contacts]

  • Request: Add a new contact

    • Headers

      x-auth-token: YOURJWT
      Content-type: application/json
      
    • Body

          {
            "name": "",
            "email": "",
            "phone": "",
            "type": "" [personal or professional]
          }
      
  • Response: 200 (application/json)

    • Body

        {
          "contact": {}
        }
      

Update Contact [PUT /api/contacts/:id]

  • Request: Update existing contact

    • Parameters

      • id: 1 (number) - An unique identifier of the contact.
    • Headers

      x-auth-token: YOURJWT
      Content-type: application/json
      
    • Body

          {
            "name": "",
            "email": "",
            "phone": "",
            "type": "" [personal or professional]
          }
      
  • Response: 200 (application/json)

    • Body

        {
          "contact": {}
        }
      

Delete Contact [DELETE /api/contacts/:id]

  • Request: Delete existing contact

    • Parameters

      • id: 1 (number) - An unique identifier of the contact.
    • Headers

      x-auth-token: YOURJWT
      
  • Response: 200 (application/json)

    • Body

        {
          "msg": "Contact removed"
        }
      

About

REST API with JWT for React course

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published