Skip to content

FE-14/greenpeace-backend

Repository files navigation

API Spec


untuk admin kita menyediakan akun admin untuk akses membuat, mengedit, menghapus user dan artikel diharapkan login sebagai admin terlebih dahulu setelah memasukan kode tokennya berikut username dan password adminnya, setelah login masukan token authorization lalu pilih Bearer Token

{
  "email": "[email protected]",
  "password": "admin"
}

1. Users dan Authorization

Field Name Type
id ObjectId
name string
email string
password string
refresh_token string

a. User Login

Request :

  • Method : POST
  • Endpoint : API/login
  • Header :
    • Content-Type: application/json
    • Accept: application/json

Body :

{
  "email": "[email protected]",
  "password": "passwoRd123!@#"
}

Response :

{
  "message": "Authentication successful!",
  "accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjEsIm5hbWUiOiJhZG1pbiIsImVtYWlsIjoiYWRtaW5AZ21haWwuY29tIiwiaWF0IjoxNjY5ODMyMzAwLCJleHAiOjE2Njk4MzU5MDB9.Ggjrd0mbCBUnaJ6pi6_KU50uvkwvCZKJAcitc0IXbvA"
}

b. add User / Register

Request :

  • Method : POST
  • Endpoint : API/register
  • Header :
    • Content-Type: application/json
    • Accept: application/json

Body :

{
  "name": "name",
  "email": "[email protected]",
  "password": "passwoRd123!@#",
  "confPassword": "passwoRd123!@#"
}

Response :

{
  "message": "User created successfully"
}

c. get All User

Request :

  • Method : GET
  • Endpoint : API/users
  • Header :
    • Accept: application/json
    • Authorization : Bearer token

Response :

{

    {
        "id": 1,
        "name": "contoh1",
        "email": "[email protected]",
        "password": "password1",
        "refresh_token": "token1"
    },
    {
       "id": 2,
        "name": "contoh2",
        "email": "[email protected]",
        "password": "password2",
        "refresh_token": "token2"
    }
}

d. get User by id

Request :

  • Method : GET
  • Endpoint : API/users/:id
  • Header :
    • Accept: application/json
    • Authorization : Bearer token

Response :

{
  "id": 1,
  "name": "contoh1",
  "email": "[email protected]",
  "password": "password1",
  "refresh_token": "token1"
}

e. edit dan update User

Request :

  • Method : PATCH
  • Endpoint : API/users/:id
  • Header :
    • Content-Type: application/json
    • Accept: application/json
    • Authorization : Bearer token

Body :

{
  "name": "contoh2",
  "email": "[email protected]"
}

Response :

{
  "message": "User updated"
}

f. get Token Refresh

Request :

  • Method : GET
  • Endpoint : API/token
  • Header :
    • Accept: application/json

Response :

{
  "accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjEsIm5hbWUiOiJhZG1pbiIsImVtYWlsIjoiYWRtaW5AZ21haWwuY29tIiwiaWF0IjoxNjY5ODMyMzAwLCJleHAiOjE2Njk4MzU5MDB9.Ggjrd0mbCBUnaJ6pi6_KU50uvkwvCZKJAcitc0IXbvA"
}

g. delete User

Request :

  • Method : DELETE
  • Endpoint : API/users/:id
  • Header :
    • Accept: application/json
    • Authorization : Bearer token

Response :

{
  "message": "User Deleted"
}

h. User Logout

Request :

  • Method : DELETE
  • Endpoint : API/logout
  • Header :
    • Accept: application/json

Response :

{
  "message": "Logout Successful!"
}

2. Artikels

Field Name Type
id ObjectId
title string
authorName string
postDescription text
postContent text
tags_1 string
tags_1 string
tags_1 string
imageUrl string

a. add Artikel

Request :

  • Method : POST
  • Endpoint : API/articles
  • Header :
    • Content-Type: application/json
    • Accept: application/json
    • Authorization : Bearer token

Body :

{
  "id": 1,
  "title": "tittle",
  "authorName": "author",
  "postDescription": "description",
  "postContent": "content",
  "tags_1": "tag1",
  "tags_2": "tag2",
  "tags_3": "tag3",
  "imageUrl": "url"
}

Response :

{
  "message": "Artikel Created"
}

b. get All artikel

Request :

  • Method : GET
  • Endpoint : API/articles
  • Header :
    • Accept: application/json

Response :

{

    {
      "id": 1,
      "title": "tittle",
      "authorName": "author",
      "postDescription": "description",
      "postContent": "content",
      "tags_1": "tag1",
      "tags_2": "tag2",
      "tags_3": "tag3",
      "imageUrl": "url"
    },
    {
      "id": 2,
      "title": "tittle2",
      "authorName": "author2",
      "postDescription": "description2",
      "postContent": "content2",
      "tags_1": "tag1_2",
      "tags_2": "tag2_2",
      "tags_3": "tag3_2",
      "imageUrl": "url2"
    }
}

d. get User by id

Request :

  • Method : GET
  • Endpoint : API/articles/:id
  • Header :
    • Accept: application/json

Response :

{
  "id": 1,
  "title": "tittle",
  "authorName": "author",
  "postDescription": "description",
  "postContent": "content",
  "tags_1": "tag1",
  "tags_2": "tag2",
  "tags_3": "tag3",
  "imageUrl": "url"
}

e. edit dan update User

Request :

  • Method : PATCH
  • Endpoint : API/articles/:id
  • Header :
    • Content-Type: application/json
    • Accept: application/json
    • Authorization : Bearer token

Body :

{
  "title": "tittle3",
  "authorName": "author3",
  "postDescription": "description3",
  "postContent": "content3"
}

Response :

{
  "message": "Artikel updated"
}

g. delete Artikel

Request :

  • Method : DELETE
  • Endpoint : API/articles/:id
  • Header :
    • Accept: application/json
    • Authorization : Bearer token

Response :

{
  "message": "User Deleted"
}