Re-use request or response parts

Every request stored in your repository can be accessed through expressions so that you can re-use its components in other requests or in assertions.

Usage example

I am testing the CRUD operations for my resource /planets.

I want to create a planet by POSTing on my /planets, then I want to verify that my planet was created and is available.

I can create:

  • a scenario Creation scenario in project Star wars API with a request Create planet that POSTs the new planet
  • a second request Verify planet existence that will retrieve the new planet's id from the response of the first request to GET the created planet on /planets/{planetId}

If the response of my first request is:

  
{
  "id": "9e5d2284-94ad-11e7-bbbc-773611cab8f7",
  "name": "Tatooine",
  "rotation_period": "23",
  "orbital_period": "304",
  "diameter": "10465",
  "climate": "arid",
  "gravity": "1 standard",
  "terrain": "desert",
  "population": "200000",
}
  

Then I can test that my planet was created by making a GET on https://my-star-wars-api.com/planets/${"Star wars API"."Creation scenario"."Create planet"."response"."body"."id"} and asserting the response code is 200 for example.

Usable elements

Requests are structured like this:

  
{
  {request name}: {string},
  "request": {
    "method"  : {string},
    "uri"     : {string},
    "headers" : {
      {header name}           : {header value}
      },
    "query" : {
      {query parameter name}  : {query parameter value}
    },
    "body"    : {string or object}
  },
  "response": {
    "headers"   : {object},
    "status"    : {
      "message" : {string},
      "code"    : {number}
    }
    "body"      : {string or object}
  }
}
  

The response contains a JSON object representing the HTTP response to the last call of the request.

You can query it in the same way you would query a standard JavaScript object, using a dotted notation.

Note: all headers names are lowercased.

Note: only the text bodies can be referenced.

This means you can reference elements of the request Get planets in project Star-wars API as follows:

  • Request URI: ${"Star-wars API"."Get planets"."request"."uri"}
  • Response status code: ${"Star-wars API"."Get planets"."response"."status"."code"}
  • Response header Content-type value: ${"Star-wars API"."Get planets"."response"."headers"."Content-type"}
  • Response body attribute id: ${"Star-wars API"."Get planets"."response"."body"."id"}

Going further

Expressions can do more, if you haven't read it yet, have a look at this page to learn more.