API TESTING

API Testing in 2026: REST, HTTP Methods and AI Agents

| API Testing, REST, HTTP Methods

API testing is where I'd tell anyone to start if they want automation work that pays off. The API is where the business rules live. A UI test tells you a button worked; an API test tells you the order was created with the right total, the right owner and the right status, and it tells you in milliseconds instead of minutes.

This guide is the one I'd hand to someone starting out, and the one I come back to when I review an existing suite. It covers the fundamentals that haven't changed: HTTP methods, status codes, headers, authentication and response contracts. It also covers the part that has changed a lot. GitHub Copilot and coding agents now write a big share of API test code, and that moves the hard part of the job from typing tests to deciding what they should check and reviewing what the agent produced.

I'll use Python with requests and pytest for the examples because they're short and readable, but every idea here carries straight over to Node, Behave, Cucumber or whatever your team runs.

API Testing using Python, Behave, VS Code & GitHub Copilot

Smarter API Test Automation — Python, Behave, VS Code, AI with GitHub Copilot & CI/CD Pipelines. Complete in a Weekend!

Learn more

What an API test actually checks

Every API test is the same shape: send a request, then make claims about the response. The skill is in choosing the claims. In practice I group them into four layers, and a test that only covers the first one is barely a test:

  • Status: did the server classify the outcome correctly (200, 201, 400, 404, 409)?
  • Contract: does the body have the documented shape, field names and types?
  • Business values: is the total right, is the owner the caller, did the state change?
  • Side effects: if I read the resource back, or call the endpoint again, does the system agree with what the first response claimed?

Keep those four in mind. They come back in every section below, and they're also the checklist I use when I review a test someone else, or something else, wrote.

HTTP methods and what to test for each

The methods tell you which behaviours matter. Testing them all the same way is the most common gap I see in beginner suites.

  • GET reads and must not change state. Test filters, pagination, missing resources (404) and resources the caller isn't allowed to see.
  • POST creates. Test the 201 and the returned body, then read the resource back. Test validation failures and what happens on a duplicate submit.
  • PUT replaces a resource and should be idempotent: sending the same PUT twice leaves the same result.
  • PATCH partially updates. Test that fields you didn't send were left alone; that's where PATCH bugs hide.
  • DELETE removes. Test that a follow-up GET returns 404 and that a second DELETE behaves the way the API documents it.

Here's a create-then-read test that covers all four layers in a few lines:

import requests


def test_create_order_persists(api_base_url, auth_headers):
    payload = {"sku": "BOOK-001", "quantity": 2}
    created = requests.post(f"{api_base_url}/orders", json=payload,
                            headers=auth_headers, timeout=10)
    assert created.status_code == 201
    order = created.json()
    assert order["quantity"] == 2
    assert order["status"] == "pending"

    fetched = requests.get(f"{api_base_url}/orders/{order['id']}",
                           headers=auth_headers, timeout=10)
    assert fetched.status_code == 200
    assert fetched.json()["sku"] == "BOOK-001"

The api_base_url and auth_headers fixtures live in conftest.py, so no test hardcodes an environment or a token.

Status codes: assert the exact one

Assert the specific code, not "something in the 2xx range". A 200 where the contract says 201, or a 500 where it says 400, is a real defect: clients branch on these values. The families are worth knowing cold (2xx success, 4xx the caller's fault, 5xx the server's fault), and so are the pairs people mix up: 401 means "I don't know who you are", 403 means "I know who you are and the answer is no". I go through the confusing ones in what REST status codes actually mean.

Then don't stop at the code. Plenty of APIs return 200 with an error object in the body. A test that only checks the status passes happily on those.

Headers, authentication and negative paths

Headers carry the content type, caching rules, rate-limit information and, most importantly, credentials. For auth I want at least these tests on every protected endpoint:

  • No token returns 401.
  • An expired or malformed token returns 401, not a 500.
  • A valid token for the wrong user or role returns 403 or 404, and never another user's data.
  • A valid token works, and the response is scoped to that caller.

Get tokens from a fixture that requests them at runtime from a test identity provider or a client-credentials flow, and keep secrets in environment variables or your CI secret store. Never commit a token, even an expired one. The pattern is covered in testing OAuth-protected APIs without hardcoding tokens.

Negative tests are where a suite earns its keep. Missing fields, wrong types, values out of range, oversized payloads. Pytest's parametrize turns a table of bad inputs into one compact test, and that table is easy for a reviewer to read.

Contracts and schemas

Field-by-field assertions catch the values you thought of. A schema check catches the field that silently disappeared or changed type. If your API publishes an OpenAPI document, validate responses against it; if not, a small JSON Schema per resource goes a long way:

from jsonschema import validate

ORDER_SCHEMA = {
    "type": "object",
    "required": ["id", "sku", "quantity", "status"],
    "properties": {
        "id": {"type": "string"},
        "sku": {"type": "string"},
        "quantity": {"type": "integer", "minimum": 1},
        "status": {"enum": ["pending", "paid", "shipped", "cancelled"]},
    },
}


def test_order_matches_schema(created_order):
    validate(instance=created_order, schema=ORDER_SCHEMA)

validate raises a ValidationError on a mismatch, which pytest reports as a failure with the offending path.

Where AI agents fit into API testing

This is the biggest change to the work. Copilot, Claude Code, Cursor and similar agents can read an endpoint, a spec or an existing test file and produce a dozen plausible tests in seconds. That's genuinely useful for breadth: parametrised negative cases, schema checks across every resource, boilerplate fixtures. It also introduces failure modes I now look for in every review:

  • Snapshot assertions. The agent calls the API, sees what comes back and asserts exactly that. The test passes today and encodes whatever bug exists today.
  • Status-only tests. Twenty tests that check for 200 and nothing else. The count looks impressive; the coverage isn't.
  • Invented behaviour. Assertions about fields or error codes the API never documented, because they looked likely.
  • Weakened tests. When a test fails, an agent asked to "fix the tests" may loosen the assertion rather than report the defect.

The fix is to give the agent the contract and the rules up front, and keep a human review gate on what gets merged. Copilot reads repository-wide guidance from .github/copilot-instructions.md, and most coding agents have an equivalent instructions file. A short section is enough:

## API test rules
- Derive expected values from openapi.yaml or the acceptance criteria, never from a live response.
- Every test asserts status AND at least one business field or schema check.
- Never relax or delete an assertion to make a test pass. Report the mismatch instead.
- Use the fixtures in conftest.py for base URL and auth; no hardcoded tokens or hosts.

When I review agent-written tests, I read the assertions first and the setup last. For each test I ask: which line would fail if the API had the bug this test claims to catch? If I can't point to one, the test goes. There's a longer list of what to watch for in where AI-generated tests get API testing wrong.

The other half of the picture: more APIs now sit in front of an LLM or are called by one as a tool. The basics above still apply to those endpoints, with two additions. When an agent calls your API as a tool, the request schema is a contract the agent has to honour, so test what happens with the malformed or partial arguments a model will eventually send. And when an endpoint returns model-generated text, you can't assert an exact string; assert structure, required fields and rules ("never includes an email address"), and run the check several times and report a pass rate instead of trusting a single green run.

A practical order to build a suite

  1. Write the smoke checks: each critical endpoint, happy path, exact status, one business field.
  2. Add auth tests for every protected endpoint.
  3. Add schema validation for every resource you return.
  4. Add parametrised negative tests for the inputs that matter.
  5. Add the multi-step flows: create, read, update, delete, and the business journeys built from them.
  6. Wire it into CI, tag a fast subset for every pull request, and run the rest on merge.

Agents help most at steps 3 and 4, where volume matters and the reviewer checks a table instead of prose. Steps 1 and 5 are where human judgment about what matters is hardest to replace.

Common mistakes to avoid

  • Tests that depend on each other's data or run order. Each test creates what it needs and cleans up after itself.
  • Hardcoded environments. One suite, many environments, chosen by configuration.
  • Sleeping instead of polling for async work.
  • Retrying failures until they pass, which hides real intermittent bugs.
  • Merging generated tests nobody read.

API testing rewards the boring habits: exact assertions, isolated data, clear failures and honest reviews. Get those right and an AI assistant multiplies a good suite instead of a bad one. If you want to build this end to end, with Python and Behave or Node and Cucumber, in VS Code with GitHub Copilot alongside, that's what my API testing courses walk through step by step.

More on API Testing

API Testing for Beginners & Career Switchers (2026)

API Testing Fundamentals for Beginners (2026)

API Testing Guide for QA Professionals in 2026

How APIs Work & How to Test Modern Web Services

How APIs Work & How to Test Modern Web Services

How APIs Work & How to Test Modern Web Services

API Testing Fundamentals: A Complete Beginner's Guide to REST APIs and HTTP Testing in 2026

API Testing: HTTP Methods, REST & the Software Lifecycle

API Testing Fundamentals: HTTP, REST & Beyond

Mastering API Testing: Essential Insights for Aspiring Testers

API Testing: HTTP Methods, REST & the Software Lifecycle

API Testing Essentials Every Tester Should Know

API Testing for Beginners: HTTP, REST & More

API Testing in 2026: REST, HTTP Methods and AI Agents

API Testing for Beginners & Career Switchers

API Testing Fundamentals: HTTP, Status Codes, Basics

API Testing for Beginners and Career Switchers (2026)

API Testing for Beginners & Career Switchers

API Testing Fundamentals: HTTP, Status Codes & REST

API Testing: HTTP Methods, REST & the Software Lifecycle

API Testing Fundamentals: What Every Beginner Needs

API Testing: HTTP Methods, REST & the Software Lifecycle

Mastering API Testing: A Comprehensive Guide for Beginners and Career Switchers

API Testing for Beginners: HTTP, REST & Core Concepts

API Testing Concepts & Trends for New Testers

API Testing for Career Switchers: REST, JSON & Security

API Testing in 2026: REST, HTTP Methods and AI Agents

API Testing Essentials: HTTP, Status Codes & REST

Mastering API Testing Fundamentals: HTTP, Status Codes, Basics in 2026

API Testing for Beginners: REST, Auth, JSON & HTTP

Unlocking the Secrets of API Testing: A Comprehensive Guide for Aspiring Testers

API Testing for Career Switchers: 2026 Starter Guide

API Testing: HTTP Methods, REST & the Software Lifecycle

API Testing Basics: HTTP Methods & REST for Beginners

API Testing Course: Python, Behave & GitHub Copilot

View all API Testing posts →

Connect & Learn

Test automation should be fun, practical, and future-ready — that's the mission of TestJeff.

Python Course Node Course Follow on GitHub