Skip to content

Latest commit

 

History

History
183 lines (143 loc) · 2.43 KB

contact.spec.md

File metadata and controls

183 lines (143 loc) · 2.43 KB

Contact API Spec

Create Contact

Endpoint: POST /api/contacts

Request Header:

  • X-API-TOKEN: token

Request Body:

{
  "first_name": "Kevin Abrar",
  "last_name": "Khansa",
  "email": "[email protected]",
  "phone": "60"
}

Response Body (Success):

{
  "data": {
    "id": 1,
    "first_name": "Kevin Abrar",
    "last_name": "Khansa",
    "email": "[email protected]",
    "phone": "60"
  }
}

Response Body (Failed):

{
  "errors": "first_name is required."
}

Get Contact

Endpoint: GET /api/contacts/{contactId}

Request Header:

  • X-API-TOKEN: token

Response Body (Success):

{
  "data": {
    "id": 1,
    "first_name": "Kevin Abrar",
    "last_name": "Khansa",
    "email": "[email protected]",
    "phone": "60"
  }
}

Response Body (Failed):

{
  "errors": "Contact ID: {contactId} not found."
}

Update Contact

Endpoint: PUT /api/contacts/{contactId}

Request Header:

  • X-API-TOKEN: token

Request Body (Success):

{
    "first_name": "Kevin Abrar",
    "last_name": "Khansa",
    "email": "[email protected]",
    "phone": "60"
}

Response Body (Success):

{
  "data": {
    "id": 1,
    "first_name": "Kevin Abrar",
    "last_name": "Khansa",
    "email": "[email protected]",
    "phone": "60"
  }
}

Response Body (Failed):

{
  "errors": "Contact ID: {contactId} not found."
}

Delete Contact

Endpoint: DELETE /api/contacts/{contactId}

Request Header:

  • X-API-TOKEN: token

Response Body (Success):

{
  "data": "OK"
}

Response Body (Failed):

{
  "errors": "Contact ID: {contactId} not found."
}

Search Contact

Endpoint: GET /api/contacts/search

Request Header:

  • X-API-TOKEN: token

Query Params:

  • name: string, either contact first_name or last_name, optional
  • phone: string, contact phone, optional
  • email: string, email address, optional
  • page: number, default 1
  • size: number, default 10

Response Body (Success):

{
  "data": [
    {
      "id": 1,
      "first_name": "Kevin Abrar",
      "last_name": "Khansa",
      "email": "[email protected]",
      "phone": "60"
    },
    {
      "id": 2,
      "first_name": "Intan",
      "last_name": "Khansa",
      "email": "[email protected]",
      "phone": "60"
    }
  ],
  "paging": {
    "current_page": 1,
    "total_page": 10,
    "size": 10
  }
}

Response Body (Failed):

{
  "errors": "Unauthorized user."
}