/elgo

Blog

Primary LanguageVue

Elgo API Documentation

Endpoints :

List of available endpoints:

  • POST /register
  • POST /login
  • GET /categories
  • POST /posts
  • GET /posts
  • GET /posts/:id
  • DELETE /posts/:id

1. GET /register

Description

  • Create a new user data

Request

body

{
  "email": "string (required)",
  "password": "string (required)"
}

Response

200 - Ok

{
  "status": "string",
  "data": {
    "id": "integer",
    "email": "string"
  }
}

400 - Bad Request

{
  "message": ["Email cannot be null", "Password cannot be null"]
}

or

{
  "message": ["Email cannot be empty", "Password cannot be empty"]
}

or

{
  "message": ["Password must be between 5 and 20 characters"]
}

or

{
  "message": ["email must be unique"]
}

2. GET /login

Description

  • Enter into the system

Request

body

{
  "email": "string (required)",
  "password": "string (required)"
}

Response

200 - Ok

{
  "status": "string",
  "access_token": "string",
  "data": {
    "id": "integer",
    "email": "string"
  }
}

401 - Unauthorized

{
  "message": "Invalid email/password"
}

3. GET /categories

Description

  • Get all the categories data

Request

headers

{
  "access_token": "string (required)"
}

Response

200 - Ok

{
  "status": "string",
  "data": [
    {
      "id": "integer",
      "name": "string",
      "createdAt": "date",
      "updatedAt": "date"
    },
    ...,
  ]
}

4. POST /posts

Description

  • Create a new post data

Request

headers

{
  "access_token": "string (required)"
}

body

{
  "title": "string (required)",
  "content": "string (required)",
  "imgUrl": "string",
  "CategoryId": "integer",
  "AuthorId": "integer"
}

Response

201 - Created

{
  "status": "string",
  "data": {
    "id": "integer",
    "title": "string",
    "content": "string",
    "imgUrl": "string",
    "CategoryId": "integer",
    "AuthorId": "integer",
    "updatedAt": "date",
    "createdAt": "date"
  }
}

400 - Bad Request

{
  "message": ["Title cannot be null", "Content cannot be null"]
}

or

{
  "message": ["Title cannot be empty", "Content cannot be empty"]
}

5. GET /posts

Description:

  • Get all posts from database

Request

headers

{
  "access_token": "string (required)"
}

Response

200 - OK

{
  "status": "ok",
  "data": [
    {
      "id": "integer",
      "title": "string",
      "content": "string",
      "imgUrl": "string",
      "CategoryId": "integer",
      "AuthorId": "integer",
      "createdAt": "date",
      "updatedAt": "date"
    },
    ...,
  ]
}

6. GET /posts/:id

Description:

  • Get post by id

Request

headers

{
  "access_token": "string (required)"
}

params

{
  "id": "integer (required)"
}

Response

200 - OK

{
  "status": "string",
  "data": {
    "id": "integer",
    "title": "string",
    "content": "string",
    "imgUrl": "string",
    "CategoryId": "integer",
    "AuthorId": "integer",
    "createdAt": "date",
    "updatedAt": "date"
  }
}

404 - Not Found

{
  "message": "Post not found"
}

7. DELETE /posts/:id

Description:

  • Delete post by id

Request

params

{
  "id": "integer (required)"
}

Response

200 - OK

{
  "message": "<entity name> success to delete"
}

403 - Forbidden

{
  "message": "You are not authorized to access this page"
}

404 - Not Found

{
  "message": "Movie not found"
}

Global Error

Response

401 - Unauthorized

{
  "message": "Invalid token"
}

500 - Internal Server Error

{
  "message": "Internal server error"
}