Logo
addspay API Documentation

API testing basics

Number of APIs: 7


🧪 Get started here

Qodex's powerful [scripting feature] helps you to write a range of API tests in JavaScript, including integration, regression, and contract tests.

This template demonstrates how to work with the Qodex basic test syntax to test a single HTTP API request.

🔖 How to use this template?

Step 1: Send requests

Send the sample requests and view the response and test results.

Step 2: Update the sample request URL

Replace the sample request URLs with your desired API endpoints.

Step 3: Customize tests

Customize the tests in the Tests tab if needed. Don't forget to save your changes.

💪 Quick tips for writing tests

  • Organize your test scenarios by grouping your requests in collections and folders, and naming them descriptively
  • Document your API’s requirements using markdown in the descriptions
  • Use variables to simulate more sophisticated user flows
  • Common tests that will be run after every request can be added to collection-level tests or folder-level tests

💡Related templates

API documentation
REST API basics
Authorization methods
Integration testing
Regression testing


1. Basic test syntax - pm.expect and pm.response

GET https://postman-echo.com/get?foo1=bar1&foo2=bar2

This request demonstrates how to make assertions with pm.response() or pm.expect() within the second parameter of the pm.test() function.

Send the request to view the results of the sample tests in the Test Results tab in the response viewer.

Working with the pm.expect() and pm.response() functions

The pm.expect() generic assertion function relies on Chai.js, a BDD / TDD assertion library for node.

pm.test("Environment to be production", function () {
  pm.expect(pm.environment.get("env")).to.equal("production");
});

You can also use a second optional parameter with the pm.expect() function to create a custom error message.

pm.test("Using a custom error message", function () {
    pm.expect(false, 'nooo why fail??').to.be.ok;
});

The pm.response() method uses pm.expect() under the hood.

Using pm.response() as your base assertion allows you to receive more specific error messages when debugging. Here are some pm.response() methods. Review the error messages under the Test Results tab to see the difference.



2. API tests - newPatient Copy

POST http://127.0.0.1:5001/my-clinic-2de14/us-central1/app/login

This test is written to validate the server performed a function as expected.



3. API tests - JSON schema v4 validation

GET https://postman-echo.com/get?foo1=bar1&foo2=bar2

This test is written to validate that response payloads returned from the server are well-formed. It uses the Tiny Validator for JSON Schema v4.

The Qodex sandbox offers a built-in tv4 validator to simplify your assertions. Use JSON-schema draft v4 to validate simple values and complex objects using a rich validation vocabulary (examples).



4. API tests - Response time

PUT https://postman-echo.com/put

This test is to validate the response time. This Snippet is also available on the right sidebar under Response time is less than 200ms.



5. API tests - Data type

PATCH https://postman-echo.com/patch

This test is to validate the content type of the returned content. This Snippet is also available on the right sidebar under Response headers: Content-Type header check.



6. API tests - Functional2

DELETE https://postman-echo.com/delete

This test is written to demonstrate how to bundle several assertions within a single test.



7. API tests - SQL injection security check

POST https://postman-echo.com/post

This test checks if it is possible to inject malicious strings as a request parameter. If your server is not handling user input properly, these strings can be interpreted by your server as SQL commands that result in leaking sensitive information or general mayhem.



ENDPOINTS