Skip to content

API Backend Routes

stevenseb edited this page Sep 5, 2024 · 1 revision

BACKEND API DOCS

User Authentication/Authorization

All endpoints that require authentication

All endpoints that require a current user to be logged in.

  • Request : endpoints that require authentication
  • Error Response: require authentication
    • Status Code: 401
    • Headers:
      • Content-Type: application/json
    • Body:
 
	{
	“message”: “Unauthorized”
	}

All endpoints that require proper authorization

All endpoints that require authentication and the current user does not have the correct role or permissions

  • Request: endpoints that require proper authorization
  • Error Response: Require proper authorization
    • Status Code: 403
    • Headers:
      • Content-Type: application/json
    • Body:
	{
	“message”: “Forbidden”
	}

Log In a User

Logs in a current user with valid credentials and returns the current user’s information

  • Require Authentication: false
  • Request Method: POST
    • URL: /api/auth/login
    • Headers:
      • Content-Type: application/json
    • Body:
	{
	“email”: [john.smith@gmail.com](mailto:john.smith@gmail.com),
	“password”: “secret”
}
  • Successful Response
  • Status Code: 200
    • Headers:
      • Content-Type: application/json
    • Body:
	{
	“user”: {
		“id”: 1,
		“email”: [john.smith@gmail.com](mailto:john.smith@gmail.com)
		“username”: “JSmith24”
}
  • Error Response: Invalid Credentials
  • Status Code: 401
    • Headers:
      • Content-Type: application/json
    • Body:
{
“Message”: “Invalid Credentials”
}
  • Error Response: Body validation errors
  • Status Code 400
    • Headers:
      • Content-Type: application/json
    • Body:
{
“message”: “Bad Request”
“errors” : {
	“credential” : “Email is required”,
	“password” : “Password is required”
	}
}

Sign Up a User

Creates a new user, logs them in as the current user and returns the current user’s information

  • Require Authentication: false
  • Request
    • Method: POST
    • URL: /api/auth/signup
    • Headers:
      • Content-Type: application/json
    • Body:
{
“username”: “Demo-User”,
“email”: “demo@email.com”,
“password” : “secret100!
}
  • Successful Response
  • Status Code: 200
    • Headers:
      • Content-Type: application/json
    • Body:
{
 “user” : {
           “id” : 1,
           “email” : “demo@email.com”,
            “username” : “Demo-User”
         }
}
  • Error Response: User already exists with the specified email
  • Status Code: 500
    • Headers:
      • Content-Type: application/json
    • Body:
{
“message”: “User already exists”,
“errors”: {
	“email”: “User with that email already exists”
	}
}
  • Error Response: User already exists with the specified username
    • Status Code: 500
    • Headers:
      • Content-Type: application/json
    • Body:
{
“message”: “User already exists”,
“errors”: {
	“email”: “User with that username already exists”
	}
}
  • Error Response: Body validation errors
    • Status Code 400
    • Headers:
      • Content-Type: application/json
    • Body:
{
“message”: “Bad Request”
“errors” : {
	“email”: ‘Invalid email,
	“username”: “Username is required”
	“password” : “Password is required”
	}
}
```js

# 

## Get all Boards owned by the Current User

### Return all the boards owned by the current user
* Require Authentication: true 
   * Request 
       * Method: GET 
       * URL: /api/boards/current
       * Body: none
    * Successful Response 
        * Status Code: 200 
    * Headers: 
        * Content-Type: application/json
    * Body:

```js
{
    “Boards”: [
{
‘id’: 1, 
“owner_id”; 1, 
“name”: “my-first-board”,
“description”: “The first of many boards to be made”,
“created_at”: “YYYY-DD-MM”“,
“updated_at”: “YYYY-DD-MM”
}
]
}

Get Board details by board id

Returns the details of a specific board

*Require Authentication: true *Request *Method: GET *URL: '/api/boards/int:id *Body: none

  * Successful Response 
    * Status Code: 200 
* Headers: 
    * Content-Type: application/json
* Body: 
{
‘id’: 1, 
“owner_id”; 1, 
“name”: “my-first-board”,
“description”: “The first of many boards to be made”,
“created_at”: “YYYY-DD-MM”“,
“updated_at”: “YYYY-DD-MM”
}

Create a Board

Creates and returns a new board

  • Require Authentication: true
    • Request: POST
      • URL: /api/boards
    • Headers:
      • Content-Type: application/json
    • Body:
{
   “owner_id”: 1,
   “name”: “new board”, 
   “description”: “a new description”
}
  • Successful Response
    • Status Code: 201
    • Headers:
      • Content-Type: application/json
    • Body:
{
“id”: 1,
	“owner_id”: 1,
        “name”: “new board”, 
        “description”: “a new description”. 
        “created_at”: “YYYY-MM-DD”
        “updated_at”:  “YYYY-MM-DD”
}
  • Error Response
    • Status Code: 400
  • Headers:
    • Content-Type: application/json
  • Body:
{
   “message”: “Bad Request”,
   “errors”: {
               “Name”: “Name is required”
	     }
}

Edit a Board

Update and returns an existing board

  • Require Authentication: true
  • Require Proper authorization: Board must belong to the user
    • Request
      • Method: PUT
      • URL: /api/boards/int:id
    • Headers:
      • Content-Type: application/json
    • Body:
{
   “name”: “updated name”,
   “description”: “updated description”
}
  • Successful Response
    • Status Code: 200
      • Headers:
        • Content-Type: application/json
    • Body:
   {
	“id”: 1,
	“owner_id”: 1,
        “name”: “updated name”, 
        “description”: “updated description”. 
        “created_at”: “YYYY-MM-DD”
        “updated_at”:  “YYYY-MM-DD”
    }
  • Error Response: Body validation errors
    • Status Code: 400
    • Headers:
      • Content-Type: application/json
    • Body:
{
    “message”: “Bad Request”,
    “errors”: {
              “Name”: “Name is required”
	      }
}
  • Error Response: Couldn’t find board with the specific id
    • Status Code: 404
    • Headers:
      • Content-Type: application/json
    • Body:
{
“message”: “Board couldn’t be found” 
}

Delete a Board

Deletes an existing board

  • Require Authentication: true

    • Require proper authorization: Board must belong to the current user
  • Request

    • Method: DELETE
    • URL: /api/boards/int:id Body: none
  • Successful Response

    • Status Code: 200
    • Headers:
      • Content-Type: application/json
    • Body:
{
   “message”: “Successfully deleted”
}
  • Error response: Couldn’t find a Board with the specified id
    • Status Code: 404
    • Headers:
      • Content-Type: application/json
    • Body:
{
“message”: “Board couldn’t be found”
}

Add a User to a Board

Adds a user to an existing board

  • Require authentication: true
    • Request
      • Method: POST
      • URL: /api/boards/int:id/users
    • Headers:
      • Content-Type: application/json
    • Body:
{
	“board_id”: 1,
	“user_id” : 1
}
  • Successful response
    • Status Code: 200
    • Headers:
      • Content-Type: application/json
    • Body:
       {
         “id”: 1, 
         “board_id”: 1,
         “user_id”: 1,
         “created_at”: “YYYY-MM-DD”
         “updated_at”: “YYYY-MM-DD” 
         }
  • Error response: Couldn’t find a Board with the specified id
    • Status Code: 404
    • Headers:
      • Content-Type: application/json
    • Body:
{
   “message”: “Board couldn’t be found”
}

LISTS

Get all Lists by a Board’s id

Returns all lists that belong to a board by specified id

  • Require Authentication: true

    • Request:
      • Method: GET
      • URL: /api/boards/int:id/lists
    • Body: none
  • Successful Response

    • Status Code: 200
    • Headers:
      • Content-Type: application/json
    • Body:
{
“Lists” : [
            {
             ‘id’: 1,
             ‘name’: ‘first list’
             ‘board_id’: 1,
             ‘created_at’: ‘YYYY-MM-DD’
              ‘updated_at’: ‘YYYY-MM-DD’
              }
            ]
 }

Create a List

Creates and returns a new List

  • Require Authentication: true
    • Request: POST
      • URL: /api/boards/int:id/lists
    • Headers:
      • Content-Type: application/json
    • Body:
{
   ‘name’: ‘a new list’
   ‘board_id’: 1 
}

Successful Response Status Code: 201 Headers: Content-Type: application/json Body:

{
  “id”: 1,
  ‘board_id’: 1
  “name”: “a new list”, 
  “created_at”: “YYYY-MM-DD”
  “updated_at”:  “YYYY-MM-DD”
 }
  • Error Response: Body validation
    • Status Code: 400
    • Headers:
      • Content-Type: application/json Body:
{
  “message”: “Bad Request”,
             “errors”: {
                        “Name”: “Name is required”
	               }
}

Edit a List

Edits and returns an existing List

  • Require Authentication: true
    • Request: PUT
    • URL: /api/lists/int:id
    • Headers:
      • Content-Type: application/json
    • Body:
{
  ‘name’: ‘updated list’
  ‘board_id’: 1 
}
  • Successful Response
    • Status Code: 201
    • Headers:
      • Content-Type: application/json
    • Body:
{
  “id”: 1,
  ‘board_id’: 1
  “name”: “updated list”, 
  “created_at”: “YYYY-MM-DD”
  “updated_at”:  “YYYY-MM-DD”
}
  • Error Response: Body validation
    • Status Code: 400
    • Headers:
      • Content-Type: application/json
    • Body:
{
  “message”: “Bad Request”,
   “errors”: {
               “Name”: “Name is required”
	      }
}

Delete a List

Deletes an existing list

  • Require Authentication: true

    • Request
    • Method: DELETE
    • URL: /api/lists/int:id
  • Body: none

  • Successful Response

    • Status Code: 200
    • Headers:
      • Content-Type: application/json
    • Body:
{
 “message”: “Successfully deleted”
}

Error response: Couldn’t find a List with the specified id 
Status Code: 404 
Headers: 
Content-Type: application/json
Body: 
{
 “message”: “List couldn’t be found”
}

Clone this wiki locally