Phone directory CRUD API

This is an example CRUD for a phone directory JSON API REST, it includes some of the most basic database operations like creating, reading, updating and deleting (CRUD).

Endpoint: http://crud.host

Status codes

Status code Reason Meaning
200 OK Your request was successful.
400 Bad Request Your request is invalid.
401 Unauthorized The access token is wrong or missing.
404 Not Found The phone number could not be found.
405 Method Not Allowed You tried to access to a route with an invalid method.
500 Internal Server Error We had a problem with our server. Try again later.

Index

  1. POST /api/phone Create a phone number
  2. GET /api/phone Get all phone numbers
  3. GET /api/phone/{id} Get specific phone number
  4. PUT /api/phone/{id} Update phone number
  5. DELETE /api/phone/{id} Delete phone number

1. Create a phone number

Insert a phone number into database.

URL

POST http://crud.host/api/phone

Parameters

Name Type Optional Description
name string Yes Name of the phone number owner.
phone string Yes Phone number of the owner.

Examples

Request
POST /api/phone HTTP/1.1
Authorization: Bearer [access token]
Content-Type: application/json
Accept: application/json
{
    "name":"Andrés Trump",
    "phone":"+52 461 111 1111",
}
Response
200 OK HTTP/1.1
Content-Type: application/json
{
    "success": true
}

2. Get all phone numbers

Retrieve all the phone numbers in the database.

URL

GET http://crud.host/api/phone

Examples

Response

Example of response

200 OK HTTP/1.1
Content-Type: application/json
[
    {
        "id": 1,
        "name": "Andrés Trump",
        "phone": "+52 461 111 1111"
    },
    {
        "id": 2,
        "name": "Margarita Clinton",
        "phone": "+52 461 111 2233"
    },
    {
        "id": 3,
        "name": "Donald John López Obrador"
        "phone": "+1 628 222 3344"
    }
]

3. Get specific phone number

Retrieve a single phone number from the database.

URL

GET http://crud.host/api/phone/{id}

Parameters

Name Type Optional Description
id int ID of the existing phone number

Examples

Response

Example response

200 OK HTTP/1.1
Content-Type: application/json
{
    "id": 1,
    "name": "Andrés Trump",
    "phone": "+52 461 111 1111"
}

4. Update phone number

Edit existing phone number in database.

URL

PUT http://crud.host/api/phone/{id}

Parameters

Name Type Optional Description
id int ID of the existing phone number.
name string Name of the phone number owner.
phone string Phone number of the owner.

Examples

Request

Example request

PUT /api/phone/{id} HTTP/1.1
Authorization: Bearer [access token]
Content-Type: application/json
Accept: application/json
{
    "name": "Enrique Peña Bush",
    "phone": "+1 628 000 3355",
}
Response

Example response

200 OK HTTP/1.1
Content-Type: application/json
{
    "success": true
}

5. Delete phone number

Remove existing phone number from database permanently.

URL

DELETE http://crud.host/api/phone/{id}

Parameters

Name Type Optional Description
id int ID of existing phone number

Examples

Response

Example response

200 OK HTTP/1.1
Content-Type: application/json
{
    "success": true
}