Requestly
FeaturesHTTP InterceptorPricingRequestly vs PostmanBlogDocsDownload

Home / API Client / API Tests & Assertions

Write API tests in JavaScript, not YAML

Assert on status codes, response bodies and JSON schemas using familiar Chai BDD syntax β€” then run the whole suite across a collection.

  • Chai BDD syntax. rq.expect(value).to.equal(expected) reads the way JavaScript tests already do.
  • Status, body and schema. Assert on the status line, specific fields, or a whole JSON schema.
  • Runs everywhere. The same assertions execute on a single send and across a full collection run.
Writing API test assertions in the Requestly API Client

Used by 300,000+ developers at 50,000+ companies

Assertions that live next to the request

An API test is only useful if it runs every time. In Requestly, tests are part of the request: write them once in the Post-response tab and they execute on every send and every collection run.

Write the assertion

Tests are JavaScript. Assertions use Chai’s BDD style, so they read close to plain English:

rq.test("Status is 200", () => {
  rq.response.to.have.status(200);
});

Reaching into a response body works the same way β€” parse it, then assert on the fields you care about.

Choose when it runs

The scripting environment has two halves. Pre-request scripts run before the request is sent, which is where you set variables or adjust headers.

Take it past one endpoint

Common patterns include contract testing (validate the response against a JSON schema), unit testing (exercise one endpoint in isolation) and error handling (confirm the API does the right thing with bad input). All three use the same rq object.

Read the documentation β†’

What you can assert

Common approaches, all written with the same rq object.

Status codes

Assert an exact status, or a category, on every response.

JSON body validation

Reach into the parsed response body and assert on the fields that matter.

Contract testing

Validate responses against a JSON schema so a shape change fails loudly.

Unit testing

Test individual endpoints in isolation, independent of the rest of the collection.

Error handling

Verify how the API behaves for invalid input, not just the happy path.

Header assertions

Check that responses carry the metadata clients depend on.

The rq object

The scripting runtime exposes the request, the response and every variable scope.

rq.test

Define a named test with a callback containing your assertions.

rq.expect

Chai BDD-style assertions for comparing values.

rq.response

Status, body, headers and timing for the response you just received.

rq.request

Method, URL, headers and body of the request that was sent.

rq.environment

Read and write environment variables from inside a test.

rq.globals

Read and write global variables that apply across collections.

Why developers switched

β˜…β˜…β˜…β˜…β˜… verified user

Requestly is the first API client that has genuinely replaced Postman for me. Everything runs locally, so my API data never goes through a cloud server. No bloat, no pressure to upgrade.

Hasan Toor
Hasan Toor
AI & Tech Educator
β˜…β˜…β˜…β˜…β˜… verified user

Postman stopped fitting the way our team works. We wanted our API collections in Git, not locked inside another tool. Requestly stores everything as plain JSON files, giving us full control over versioning and reviews.

NIJ Ruvos
NIJ Ruvos
Engineering Lead
β˜…β˜…β˜…β˜…β˜… verified user

We migrated from Postman to Requestly's API Client and it has been a great experience. Storing collections locally, keeping them in Git, and working with simple JSON files made the transition seamless.

Harry S
Harry S
Principal Engineer at Tapistro

Related features

More of what the Requestly API Client does.

AI Test Case Generator

Write tests from a plain-English prompt

Requestly CLI

Run collections in CI

Collection Runner

Run a whole collection in order

Data-Driven Testing

Drive collection runs from a CSV or JSON file

DevTools

Console, network and resolved-variable inspection in one panel

Generate Client Code

Export requests to 20+ languages

See all features β†’

Frequently Asked Questions

Requestly uses Chai.js BDD-style assertions, so rq.expect(value).to.equal(expected) reads the way you would expect if you have written JavaScript tests before.

Tests live in the Scripts section of a request. Post-response scripts run after a response arrives and are where assertions normally go. Pre-request scripts run before the request is sent.

Yes. Every request keeps its tests during a collection run, so a run reports pass and fail per request. See the Collection Runner.

Yes. Schema validation lets you assert a response against a JSON schema, which catches contract changes that field-level assertions would miss.

Assert on your APIs, not just eyeball them

Write a test in the Post-response tab and it runs on every send and every collection run. Available on macOS, Windows and Linux.

macOS, Windows & Linux