Interview Questions for API Testing 2025

HOME

https://www.qaautomation.expert
Host: www.example.com
User-Agent: Mozilla/5.0
Accept: text/html
  {
     "username": "exampleuser",
     "password": "examplepassword"
   }
   

Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=
 x-api-key: YOUR_API_KEY

'or 1=1--
"and 1=1--
echo "malicious" >> /var/www/html/index.html
rm file.txt; cat /etc/passwd

https://api.example.com/items?page=2&limit=50
https://api.example.com/products?category=electronics&price<1000

name: API Tests

on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - main

jobs:
  test:
    runs-on: ubuntu-latest

    steps:
    - name: Checkout code
      uses: actions/checkout@v2

    - name: Set up Node.js
      uses: actions/setup-node@v2
      with:
        node-version: '14'

    - name: Install Newman
      run: npm install -g newman

    - name: Run API tests with Newman
      run: newman run test.json

{
  "token": "eyJhbGciOiJIUzI1NiIsInR..."
}

import io.restassured.http.ContentType;
import org.json.JSONObject;
import org.junit.jupiter.api.Test;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.equalTo;

public class APITests {

        String BaseURL = "https://reqres.in/api";

    @Test
    public void getUser() {  

        // GIVEN
        given()
                .contentType(ContentType.JSON)

                // WHEN
                .when()
                .get(BaseURL + "/users/2")

                // THEN
                .then()
                .statusCode(200)
                .body("data.first_name", equalTo("Janet"))
                .log().all();

    }

}

Use Case Examples**:
  - Login authentication: The client needs the server's response before proceeding.
  - Fetching data: The client requires the result immediately to display to the user.
**Use Case Examples**:
  - File upload or processing: The server processes the file and sends a notification when done.
  - Notification systems: Sending push notifications to multiple devices.

Leave a comment