API Testing

REST API Testing Examples: Practice Scenarios for QA Testers

Practice REST API testing with realistic request and response scenarios for creation, validation, authorization, retrieval, errors, and data checks.

API Testing guideReviewed by TestingCredentials.com editorsLast updated May 8, 2026
In this guide

Good REST API testing checks more than whether a request returns a successful status code. You also need to test the data contract, business rules, error handling, permissions, state changes, and what the system stores after the request.

The examples below use a fictional customer API. They are not tied to any vendor or public service. The HTTP status codes shown are examples based on standard HTTP semantics in RFC 9110. In a real project, the API contract is the authority for the behavior your product promises.

Fictional API Rules

Assume the API supports these operations:

  • POST /customers creates a customer.
  • GET /customers/{id} retrieves a customer.
  • PUT /customers/{id} replaces the stored representation for a customer.

For this exercise, a customer has name, email, and account_type. Name and email are required. Email addresses must be unique. Account type must be either Standard or Business.

Example 1: Create a Valid Customer

Request:

POST /customers
Content-Type: application/json

{
  "name": "Jordan Lee",
  "email": "[email protected]",
  "account_type": "Standard"
}

If the API contract says a successful creation returns 201 Created, verify all of the following:

  • The status is 201.
  • The response body contains the fields promised by the contract.
  • The customer identifier has the expected type and format.
  • The returned name, email, and account type match the accepted request.
  • A follow-up GET returns the stored customer.
  • No unexpected fields containing sensitive data appear in the response.

The last two checks matter because a response can look correct even when the system stored the wrong data or exposed more data than intended.

Example 2: Test Required Fields and Invalid Values

Now vary one rule at a time:

{
  "name": "Jordan Lee",
  "account_type": "Standard"
}

Email is missing, so the request should fail according to the API contract. Then try:

  • An empty email
  • An email value that violates the documented format rule
  • An unsupported account type
  • A missing name
  • A duplicate email address

Do not assume every API must use the same client-error status for these cases. RFC 9110 defines several 4xx status codes, but the product contract should say which one applies. Your test should verify both the documented status and the error body. A useful error response should also avoid leaking internal implementation details.

Example 3: Retrieve an Existing and Missing Customer

After creating customer 142, test:

GET /customers/142

Verify the expected success status, response schema, field values, and any authorization rules.

Then request an identifier that does not exist:

GET /customers/999999

If the contract specifies 404 Not Found, confirm the status and the documented error response. Also check that the response does not accidentally return another customer’s data.

Example 4: Test Object-Level Authorization

Assume user A owns customer record 142 and user B should not be able to read or change it. Authenticate as user B and request:

GET /customers/142

The most important assertion is not a particular status code. It is that user B does not receive user A’s protected data. The exact status may depend on the API’s security design and contract.

This test targets a well-documented API risk. The OWASP API Security Top 10 describes broken object-level authorization as a problem that can occur when attackers manipulate object identifiers to reach data they should not be allowed to access.

Repeat the authorization check for update operations, not only reads.

Example 5: Replace a Customer and Verify the Stored State

Suppose the contract uses PUT to replace the customer’s stored representation:

PUT /customers/142
Content-Type: application/json

{
  "name": "Jordan Lee",
  "email": "[email protected]",
  "account_type": "Business"
}

After the request succeeds, retrieve the customer again and verify that the stored state matches the replacement rules in the contract. Check that:

  • The account type changed to Business.
  • Fields that should remain the same still have the correct values.
  • The update did not create a duplicate customer.
  • A repeated request behaves consistently with the API’s documented semantics.

RFC 9110 defines PUT as an idempotent method, meaning multiple identical requests are intended to have the same effect as one request. That does not mean every response must be byte-for-byte identical.

What to Check Beyond the Status Code

For each API test, think in layers:

  • Protocol: method, status, headers, and content type
  • Contract: required fields, types, formats, and allowed values
  • Business rules: uniqueness, limits, transitions, and other product rules
  • Data: what was actually created or changed
  • Authorization: who can read or change each resource
  • Error handling: useful, consistent errors without unintended data exposure
  • Side effects: related records, messages, or state changes the request is supposed to trigger

For a broader introduction, read API Testing for QA Testers. For planning coverage on a real endpoint, use the REST API Testing Checklist.

Tools and Structured Learning

If you want to explore categories of API testing tools, AT*Tools includes an API Testing section. AT*SQA states that it has not independently tested the listed products, so use the directory to discover options and evaluate them against your own needs.

AT*SQA currently has a three-part API Testing AT*SkillStack: Introduction and Testing Planning and Design; REST API, gRPC, and GraphQL; and Environments, Tools, and Future Proofing. The REST API, gRPC, and GraphQL Micro-Credential includes REST characteristics, data contracts, headers, response validation, data handling, versioning, paths and parameters, and API test design. A credential can document knowledge, while examples like these give you a place to practice applying it.

Turn examples into repeatable checks

Use the companion checklist to add validation, authorization, and cleanup checks. Review the official REST API topic if it fits your work.

FAQ

Questions testers ask

Should every API error return 400?

No. HTTP defines multiple 4xx client-error statuses, and the API contract should specify how the product uses them. Test the documented behavior rather than forcing every validation problem into one status.

Is checking the response body enough?

No. Also verify status and headers where relevant, stored data, permissions, side effects, and follow-up behavior. A correct-looking response can hide an incorrect state change.

Should authorization tests use another user’s object ID?

Yes, when your authorized test environment allows it. A user should not gain access to another user’s protected object simply by changing an identifier. Use test accounts and data that you are permitted to access.