Rest Project

Overview

Rest Project is created to do rest api (actually any http/https request) testing or autotest. Each rest project case can organize any numbers of Apis as you like.

Here is a virsual view of a rest project case:

  • left side is the rest project navigation menu. use “+New” or “-Delete” button to manage these projects.
  • right side is the API sets and api execution history.

Architecture

In Api set, you can create two types of API:

  • Rest API:
    a http or https request (normally we call it Rest API) with a response validator. The http/https request can be defined visually and can also be advanced built by a script block - PreRequest.
    The workflow of execution of one Rest API is:

Architecture

  • Script:
    a block of code that will be called while execucation.

Rest Project supports both Python and Golang programming, we can choose what we like at the project case creation.

Rest Project/Case

Create Rest Project Case

To create a Rest Project Case through the web portal, you can :

  1. login to restbird portal and switch to “Rest Project” Tab. Click ”+ New” button.

RestBird Login

  1. Create a Rest Directory (test)

RestBird Dir

  1. Create a Rest Case (hello-google) under the Directory we just created

RestBird Case

Now, the ‘hello-google’ case was created.

RestBird Case

Tips

Beside the web portal, you can also create project cases directly under the porject directory of the host OS.

Script Language

When you create a rest project case, you need to select a script language between Python and Golang.

Once the script language is selected, all rest apis in that case will use that language for advanced programming, like Pre-Request , ResponseValidation, Pure Script.

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.

Pure Script

‘Pure Script’ is just a block of code, which will be called like sending a http request while execution. You can do anything here, like access the varibles, sleep a while before sending next rest api, call other apis…

Architecture

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

Varibles

we have two types of varibles: Local Varibles and global varibles, while Api testing.

Local Varibles

Every rest project case can bind a group of varibles. All the varibles in the group can be used and updated at request building, response validation or Pure script.

  • While visually request building, we can use {{varible-name}} in any place like : URL, Header, or Body. it will automaticly be replaced to the target varible value at run time.

  • In programming script block, like Pre-Request Script, Response Validation Script and Pure Script, we can also access or update these varibles through a programing interface.

    Different programming languag may have diffent interfaces, please check the examples there.
    In golang based cases, we can get or set the varibles by:

    value = ctx.GetVars(key)
    ctx.SetVars(key, value)

Bind a project case to a group of varibles by click the “vars” button under the case.

Architecture

we can also add/delet/modfy these varible definitions in the varible editor.

Architecture

Global Varibles

sometimes we would like to share something between a runing rest project and a runing tasks, we can use following method to access the global shared varibles

  • callapi.SetGlobalString(key, value)
  • error, value = callapi.GetGlobalString(key)

Run Rest Api

There are two ways to run a created Api.

  1. while the Api development phase, we normally click “Run Test” button under a api to run that api and check the result.

RestBird Login

  1. when all Apis are created, we could select a group of Apis and click the “Run Selected” button on the page to run this group of api.

RestBird Login

Histories

For every run of a rest api or a group of api, a history record will be generated under the History tab:

Architecture

click the row of the history table, you will see the detail infomation of that execution.

Architecture

Misc functions

Copy API

Select the Apis you want to copy, then click copy button. we can copy Rest APis to current rest project or any other rest project.

Import API

Click import button to the 3rd party API definitions, like swagger.