Rest Api

Add Rest Api

Take ‘hello-google’ case for example, let’s add a rest api to test it.

  1. login to restbird portal and switch to “Rest Project” Tab. Click ”+ New” button to add a rest api (Actually could any http request).

RestBird Login

  1. Click the api to see the detail, and modify all the field to build the http request.

RestBird Login

Visually Request Building

Here is a visual view of an Rest Api:

Architecture

A Rest API definition includes 6 parts:

  • Http Request Definition:

    • Url/Method:
    • Authentication:
    • Req Headers:
    • Req Body:
    • Pre-Request Scripts:
  • Http Response Validation:

    • Response Check Scripts:

To build a http request, you don’t have to write a single line of code if you like. Just provide all the http request infomation under tabs Url/Method, Authentication, Req Headers and Req Body.

Environment varibles can also be used in all fields, we will talk it later.

Pre-Request Script

Some times the visually request builder is not enough, we want to do more advanced jobs by programming the Http Request. The pre-Request callback Script is the place we can do it.

Base on the script language you select while creating the case, the ‘pre-request’ callback script could be a block of Python script or golang script, which will be called just before we send out the http request. So it could overwrite any infomation you provided through the visually request building.

Here is a golang example to add “Header” to the Http Request in callback:

Architecture

Here is a python example to add “Header” to the Http Request in callback:

Architecture

Tips

Click the ‘Example’ button under the ‘pre-request’ tab, you will bundles of examples codes of pre-request scripts. You don’t even to be farmilar with that programing language, you can do program here.

Response Validation Script

Response Validation Script is a callback script that will be called to check the HTTP Response when we received it.

We can check any content of the response, like status code, res header and body data. Then return true if everything looks fine, or fasle if you think the Response is not expected.

Architecture

Based on the script language you select while creating the case, the ‘responsevalidation’ callback script could be a block of Python script or golang script.

Tips

Click the ‘Example’ button under the ‘responsevalidation’ tab, you will bundles of examples codes of responsevalidation scripts. You don’t even to be farmilar with that programing language, you can do program here.