Skip to content

alicez0626/DiaGram-backend

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DiaGram API Server

To run the server locally, run:
npm start

Signup

Creates a user

  • URL

    /signup

  • Method:

    POST

  • URL Body

    Required:

    username: <String>
    password: <String>
    accessCode: <String>

  • Success Response:

    • Code: 200
      Content:
      { jwt: <String>, user: { _id: <String>, username: <String> } }
  • Error Response:

    • Code: 400 BAD REQUEST
      Content:
      { errors : [ "DUPLICATE_USERNAME", "INVALID_ACCESS_CODE", "INVALID_PASSWORD" ] }

Login

Grant session to a user given the username and password

  • URL

    /login

  • Method:

    POST

  • URL Body

    Required:

    username: <String>
    password: <String>

  • Success Response:

    • Code: 200
      Content:
      { jwt: <String>, user: { _id: <String>, username: <String> } }
  • Error Response:

    • Code: 400 BAD REQUEST
      Content:
      { errors : [ "INVALID_CREDENTIALS" ] }

Get Post

Get posts for app feed

  • URL

    /posts

  • Method:

    GET

  • URL HEADER

    Required:

    Authorization: "Bearer ${jwt}"

  • Success Response:

    • Code: 200
      Content:
      [
        {
          _id: <String>,
          tite: <String>,
          body: <String>,
          userType: enum { patient, doctor },
          private: <Boolean>
          comments: [
            {
              _id: [included: if userType == doctor] ,
              userType: enum { patient, doctor },
              body: <String>,
            },
            ...
          ]
        },
        ...
      ]
      
  • Error Response:

    • Code: 403 UNAUTHORIZED
      Content:
      { errors : [ "UNAUTHORIZED", "SESSION_EXPIRED" ] }

Make Post

Make a new post

  • URL

    /posts

  • Method:

    POST

  • URL HEADER

    Required:

    Authorization: "Bearer ${jwt}"

  • URL Body

    Required:

    title: <String>
    body: <String>

    Optional:

    private: <Boolean>

  • Success Response:

    • Code: 200
      Content:
      {
        _id: <String>,
        tite: <String>,
        body: <String>,
        userType: enum { patient, doctor },
        private: <Boolean>
        comments: []
      }
      
  • Error Response:

    • Code: 400 BAD REQUEST
      Content:
      { errors : [ "EMPTY_TITLE", "EMPTY_BODY" ] }

    • Code: 403 UNAUTHORIZED
      Content:
      { errors : [ "UNAUTHORIZED", "SESSION_EXPIRED" ] }

Common Error Response

  • INTERNAL SERVER ERROR
    happens when there is something wrong with the server internally

    • Code: 500
      Content:
      { errors : [ "INTERNAL_SERVER_ERROR" ] }
  • NOT FOUND
    happens the URL does not exist

    • Code: 400
      Content:
      { errors : [ "NOT_FOUND" ] }

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%