Table of Contents

Web APIs

Screenplay may be used to interact with Web APIs. Key to this is Ability class MakeWebApiRequests, along with a number of performables and types which represent API endpoints.

Use WebApiBuilder to simplify usage

The section & table below indicates the combinations of 'endpoint' & performable to use for several common use cases. If the correct endpoint has been used though, the WebApiBuilder class will make it very easy to select the correct performable, by type inference.

For any requests which are expecting to read a response as a JSON string, to be deserialized, use an overload of GetTheJsonResult from the static web API builder. For any other requests, use an overload of SendTheHttpRequest.

The recommended way to use this builder is via using static CSF.Screenplay.WebApis.WebApiBuilder; in the source file for a custom performable.

Combinations of endpoints & performables for common usages

The performable which should be used, along with the approproate endpoint type depends upon your use case, summarised in the table below. The table is organised by the expected body/content of the HTTP request, the request payload and the expected type of the response body.

Where None is listed, this usually means that either the request or response have no body, such as an HTTP GET request that does not send a body or an empty response. In the case of responses this might alternatively mean that the response body will be ignored or will not be interpreted as an instance of any particular type.

Request payload Response type Endpoint type Performable type
None None Endpoint SendTheHttpRequest
None Deserialized with custom logic Endpoint<TResponse> SendTheHttpRequestAndGetTheResponse<T>
None Deserialized from JSON Endpoint<TResponse> SendTheHttpRequestAndGetJsonResponse<T>
Serialized with custom logic None Derive from ParameterizedEndpoint<TParameters> SendTheHttpRequest
Serialized with custom logic Deserialized with custom logic Derive from ParameterizedEndpoint<TParameters,TResponse> SendTheHttpRequestAndGetTheResponse<T>
Serialized with custom logic Deserialized from JSON Derive from ParameterizedEndpoint<TParameters,TResponse> SendTheHttpRequestAndGetJsonResponse<T>
Serialized with JSON None JsonEndpoint<TParameters> SendTheHttpRequest
Serialized with JSON Deserialized with custom logic JsonEndpoint<TParameters,TResponse> SendTheHttpRequestAndGetTheResponse<T>
Serialized with JSON Deserialized from JSON JsonEndpoint<TParameters,TResponse> SendTheHttpRequestAndGetJsonResponse<T>
Tip

The rule to decide which types of endpoint & performable to choose is: Choose the endpoint type based upon the needs of the request, adding an extra generic type parameter if the response is to be strongly-typed. Choose the performable type based upon how you intend to read the response.