Reusing parts of requests or responses - Cloud

Talend Cloud API Tester User Guide

Version
Cloud
Language
English
Product
Talend Cloud
Module
Talend API Tester
Content
Design and Development > Testing APIs
Last publication date
2024-03-27
Every request stored in your repository can be accessed through expressions so that you can reuse its components in other requests or in assertions.

Use case

You are testing the CRUD (Create, Read, Update, Delete) operations for your resource /planets.

You want to create a planet by posting on your /planets, then you want to verify that your planet was created and is available.

You 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 your 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 you can test that your planet was created by creating 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 as follows:

{
  {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 in lowercase, and 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"}