API_Reqres_Testing

Hi! this is the documentation created by myself for the API Reqres.in. Here you'll find the documentation for each endpoint as well as the test cases and the code for the automation test using Postman.

Base Url: https://reqres.in

Endpoint: List Users

URL: /api/users?page={number}

Method: GET

Description:

This point retrieves a paged list of users. You can specify the page number in the request to get a specific user page.

Query Parameters:

  • Page: (optional): An integer that specifies the page of results to obtain.

Successful Request:

  • Code: 200 ok
  • Content: A JSON object that contains the following information:
    • page: (int) The number of the current page.
    • per_page: (int) The number of users per page.
    • total: (int) The total of users avaible.
    • total_pages: (int) the total pages available in the api.
    • data: (array) An array of users, where each user contains:
      • id: (int) The unique ID of the user.
      • email: (string) The user's email.
      • first_name: (string) First name of the user.
      • last_name: (string) Last name of the user.
      • avatar: (string) The URL of the user's avatar.
    • support: (object) An object that contains the URL for contribute with the reqres.in proyect:
      • url: (string) url for the support page for the reqres proyect.
      • text: (string) a basic description for why support the proyect.

Example of response:

{
    "page": 2,
    "per_page": 2,
    "total": 12,
    "total_pages": 2,
    "data": [
    {
        "id": 7,
        "email": "michael.lawson@reqres.in",
        "first_name": "Michael",
        "last_name": "Lawson",
        "avatar": "https://reqres.in/img/faces/7-image.jpg"
    },
    // ... more users
  ],
  "support": {
        "url": "https://reqres.in/#support-heading",
        "text": "To keep ReqRes free, contributions towards server costs are appreciated!"
    }
}

Examples of code for call the endpoint:

  • curl:
curl -X GET "https://reqres.in/api/users?page=2"
  • javascript (Fetch):
async function fetchUsers(page) {
  try {
    const response = await fetch(`https://reqres.in/api/users?page=${page}`);
    const data = await response.json();
    console.log(data);
  } catch (error) {
    console.error('Error:', error);
  }
}

fetchUsers(2); // Calls the funtion with the page number you want.
  • Python (Requests):
import requests

response = requests.get("https://reqres.in/api/users?page=2")
data = response.json()
print(data)

Errors:

  • Code: 200 ok

  • Content:

    {
        "page": 8,
        "per_page": 6,
        "total": 12,
        "total_pages": 2,
        "data": [],
        "support": {
            "url": "https://reqres.in/#support-heading",
            "text": "To keep ReqRes free, contributions towards server costs are appreciated!"
        }
    }
    
  • Description: This "Error" is actually an expected behavior, API will only return the data shown above.

Endpoint: Single User

URL: /api/users/{id}

Method: GET

Description:

Retrieve detailed information of a single user by using their unique ID.

Query Parameters:

id (int): The unique ID of the user.

Successful Request:

  • Code: 200 ok status
  • Content: (Obj) A JSON object that contains the following information:
    • data: A Object that contains the following information:
      • id: (int) The unique ID number for the user.
      • email: (string) User's email address.
      • first_name:(string) User's first name.
      • last_name:(string) User's last name.
      • avatar:(string) Url to the User's avatar image.
      • support: (object) An object that contains the URL for contribute with the reqres.in proyect:
        • url: (string) url for the support page for the reqres proyect.
        • text: (string) a basic description for why support the proyect.

Example of response:

{
    "data": {
        "id": 2,
        "email": "janet.weaver@reqres.in",
        "first_name": "Janet",
        "last_name": "Weaver",
        "avatar": "https://reqres.in/img/faces/2-image.jpg"
    },
    "support": {
        "url": "https://reqres.in/#support-heading",
        "text": "To keep ReqRes free, contributions towards server costs are appreciated!"
    }
}

Examples of code for call the endpoint:

  • curl:
curl -X GET "https://reqres.in/api/users/2"
  • javascript (Fetch):
async function fetchSingleUser(userId) {
  try {
    const response = await fetch(`https://reqres.in/api/users/${userId}`);
    const data = await response.json();
    console.log(data);
  } catch (error) {
    console.error('Error:', error);
  }
}

fetchSingleUser(2); // Calls the function with the number of the user you want.

  • Python (Requests):
import requests

response = requests.get("https://reqres.in/api/users/2")
data = response.json()
print(data)

Errors:

  • Code: 404 not found

  • Content:

    {}
    
  • Description: This error is returned when a non-existing user is selected, and empty object will be returned with a 404 status.

Endpoint: Single User Not Found

URL: /api/users/{id}

Method: GET

Description:

When a request is done to a inexisting user ID, the API returns an empty objet with a 404 error message.

Query Parameters:

id (integer): a user ID that does not exist in the database.

Example of response:

  • code: 404 not found
  • content:
  {}

Examples of code for call the endpoint:

  • Curl:
curl -X GET "https://reqres.in/api/users/23" -H "accept: application/json"

  • Javascript:
async function getUser() {
  try {
    const response = await fetch("https://reqres.in/api/users/23");
    if (!response.ok) {
      throw new Error('User not found');
    }
    const data = await response.json();
    console.log(data);
  } catch (error) {
    console.error('Error:', error);
  }
}

getUser();
  • Python:
import requests

response = requests.get("https://reqres.in/api/users/23")

if response.status_code == 404:
    print("User not found")
else:
    user = response.json()
    print(user)

Errors:

  • Code: 404
  • Content:
  {}

This status code is expected when the ID is invalid, and the API will return an empty object.

List Resource

URL: /api/unknown?page={number}

Method: GET

Description:

This endpoints returns a list of different colors with their ID, name, Hexadecimal code and the panton code (world standar for the color code).

Query Parameters:

  • page (optional): by default each page has 6 different colors, in total there are 2 pages.

Successfull Request:

  • Code: 200 OK
  • Content: A JSON object that contains the following information:
    • page: (int) The current page number.
    • per_page: (int) The number of items per page.
    • total: (int) The total number of items.
    • total_pages: (int) The total number of pages.
    • data: (array) An array of objects where each object contains information about a resource:
      • id: (int) The unique ID number for the resource.
      • name: (string) The name of the resource.
      • year: (int) The year of the resource.
      • color: (string) The color associated with the resource.
      • pantone_value: (string) The pantone value of the resource.

Example of response:

{
    "page": 1,
    "per_page": 6,
    "total": 12,
    "total_pages": 2,
    "data": [
        {
            "id": 1,
            "name": "cerulean",
            "year": 2000,
            "color": "#98B2D1",
            "pantone_value": "15-4020"
        },
        // ... other resource objects
    ],
    "support": {
            "url": "https://reqres.in/#support-heading",
            "text": "To keep ReqRes free, contributions towards server costs are appreciated!"
        }
}

Examples of code for call the endpoint:

  • Curl:
curl -X GET "https://reqres.in/api/unknown" -H "accept: application/json"
  • Javascript:
  async function getResourceList() {
    try {
      const response = await fetch("https://reqres.in/api/unknown?page=1");

      if (!response.ok) {
        throw new Error('Network response was not ok');
      }

      const data = await response.json();
      console.log(data);
    } catch (error) {
      console.error('Error:', error);
    }
  }

  getResourceList();
  • python:
import requests

response = requests.get("https://reqres.in/api/unknown?page=1")

if response.status_code == 200:
    data = response.json()

    print(data)
else:
    print("Error fetching the resources")

Errors:

  • Code: 200 ok
  • Content:
{
    "page": 987,
    "per_page": 6,
    "total": 12,
    "total_pages": 2,
    "data": [],
    "support": {
        "url": "https://reqres.in/#support-heading",
        "text": "To keep ReqRes free, contributions towards server costs are appreciated!"
    }
}
  • Description: This "Error" is actually an expected behavior, API will only return the data shown above when and non-existing page number is selected.

Single Resource

URL

/api/unknown/{id}

Method

GET

Description

Retrieves information about a specific resource by its ID.

Query Parameters

id unique ID of the resource.

Successful Request

  • Code: 200 OK
  • Content: A JSON object that includes details about the resource and support information.
    • data: (object) Contains details about the resource:
      • id: (int) The unique identifier for the resource.
      • name: (string) The name of the resource.
      • year: (int) The year associated with the resource.
      • color: (string) The color representation of the resource.
      • pantone_value: (string) The pantone value linked to the resource.
    • support: (object) Contains support information for the reqres project:
      • url: (string) The URL to the support page for the reqres project.
      • text: (string) A short description of why to support the project.

Example of Response

{
  "data": {
    "id": 2,
    "name": "fuchsia rose",
    "year": 2001,
    "color": "#C74375",
    "pantone_value": "17-2031"
  },
  "support": {
    "url": "https://reqres.in/#support-heading",
    "text": "To keep ReqRes free, contributions towards server costs are appreciated!"
  }
}

Examples of code for call the endpoint:

  • Curl:
curl -X GET "https://reqres.in/api/unknown/2" -H "accept: application/json"
  • Javascript:
async function getSingleResource() {
  try {
    const response = await fetch("https://reqres.in/api/unknown/2");

    if (!response.ok) {
      throw new Error('Network response was not ok: ' + response.statusText);
    }

    const data = await response.json();

    console.log(data);
  } catch (error) {
    console.error('Error:', error);
  }
}

getSingleResource();
  • Python:
import requests

response = requests.get("https://reqres.in/api/unknown/2")

if response.status_code == 200:
    data = response.json()

    print(data)
else:
    print('Error:', response.status_code, response.text)

Errors:

  • Code: 404 Not Found
  • Content:
{}
  • Description: The API will return a 404 error when a non-existing ID is requested, also it will return an empty object.

Single Resource Not Found

URL

/api/unknown/:id

Method

GET

Description

This endpoint retrieves information about a specific resource by its unique ID. If the resource with the specified ID does not exist, the endpoint responds with an error.

Path Parameters

  • id: (int) The unique identifier for the resource.

Error Response

  • Code: 404 Not Found
  • Content:
{} (an empty JSON object)
  • Description: This error response indicates that the requested resource could not be found. This usually occurs when the resource with the specified ID does not exist in the database.

Example of Error Response

When a non-existent resource ID is requested, the server responds with a 404 Not Found status code and an empty JSON object as shown below:

{}

Examples of code for call the endpoint:

  • Curl:

    curl -X GET "https://reqres.in/api/unknown/23" -H "accept: application/json"
    
  • Javascript:

    async function getNonExistentResource() {
      try {
        const response = await fetch("https://reqres.in/api/unknown/23");
    
        if (!response.ok) {
          throw new Error(`HTTP error! status: ${response.status}`);
        }
    
        const data = await response.json();
    
        console.log(data);
      } catch (error) {
        console.error('Error:', error.message);
      }
    }
    
    getNonExistentResource();
    
  • Python:

    import requests
    
    response = requests.get("https://reqres.in/api/unknown/23")
    
    if response.status_code == 404:
        print("Resource not found.")
    else:
        data = response.json()
        print(data)
    

Create User

URL:

/api/users

Method:

POST

Description:

Creates a new user with the provided information.

Body Parameters:

  • name (string): The name of the user.
  • job (string): The user's job title.

Example:

{
    "name": "morpheus",
    "job": "leader"
}

Successful Request:

  • Code: 201 Created
  • Content: A JSON object containing the newly created user's information, including a unique ID and creation timestamp.

Example of Response:

{
  "name": "morpheus",
  "job": "leader",
  "id": "619",
  "createdAt": "2024-03-14T01:41:19.491Z"
}

Examples of code for call the endpoint:

  • Curl:
curl -X POST "https://reqres.in/api/users" -H "Content-Type: application/json" -d '{"name": "morpheus", "job": "leader"}'

  • Javascript:
async function createUser() {
try {
  const response = await fetch("https://reqres.in/api/users", {
    method: "POST",
    headers: {
      "Content-Type": "application/json"
    },
    body: JSON.stringify({ name: "morpheus", job: "leader" })
  });

  if (!response.ok) {
    throw new Error(`HTTP error! status: ${response.status}`);
  }

  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error("Error:", error);
}
}

createUser();

  • Python:
import requests
response = requests.post("https://reqres.in/api/users", json={"name": "morpheus", "job": "leader"})
if response.status_code == 201:
  print(response.json())
else:
  print('Error:', response.status_code, response.text)