The RapidAPI Developer Hub

Welcome to the RapidAPI developer hub. You'll find comprehensive guides and documentation to help you start working with RapidAPI as quickly as possible, as well as support if you get stuck. Let's jump right in!

Get Started    Guides

Executing Code in Tests

For certain use cases, the built-in test actions may not be enough to give you the full flexibility to thoroughly test your APIs. In these cases, you can add custom code actions that will execute when your tests are called.

To add code in your test, add the action.

Your code should export a function through module.exports. This is the basic boilerplate:

module.exports = (context) => {
    return {};

The function takes one argument — context, which is an object holding all the variables in the test flow (data returned from previous API calls, test variables, environment variables, etc).

The function should return an object. Any data in the object will be added to the test context and can be used by subsequent actions. See the following test flow as an example:

Intentionally Failing Tests

In addition to adding and modifying data, you may want to use code snippets to perform complex validations on data (like ragex-matching strings or summing up numbers). If you want to cause a test to fail, just throw an exception in your code like so:

module.exports = (context) => {
    throw "This action will fail the test"

Whatever message you send in the exception will be added to the test results:

Updated about a month ago

Executing Code in Tests

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.