Class JsonEndpoint<TParameters, TResult>
- Namespace
- CSF.Screenplay.WebApis
- Assembly
- CSF.Screenplay.WebApis.dll
Base type for a Web API endpoint which accepts a request payload in the form of a strongly typed object serialized to JSON string, and which is expected to return a response body that exposes a strongly-typed object.
public class JsonEndpoint<TParameters, TResult> : ParameterizedEndpoint<TParameters, TResult>, IHasName
Type Parameters
TParameters
The type of the parameters object which is required to create an HTTP request message
TResult
The type of response that the endpoint is expected to return.
- Inheritance
-
ParameterizedEndpoint<TParameters, TResult>JsonEndpoint<TParameters, TResult>
- Implements
- Inherited Members
Remarks
There are several concrete types of endpoint available, all of which derive from EndpointBase, for more information about the purpose of endpoints and how they are used, see the documentation for that base type.
The manner in which this endpoint exposes the strongly typed response object is undefined within the endpoint itself. It is down to a performable implementation to deserialize the result object from the HTTP response content.
Developers are welcome to create specialized derived types based upon this or other subclasses of EndpointBase if they have specific needs. Derived classes should overrideGetHttpRequestMessageBuilder(TParameters) with a method that calls the base implementation and then further manipulates the message builder before returning it.
When deriving from this class, developers are strongly encouraged to set the Name property to a human-readable name for this endpoint. This will improve the readability of reports.
For more information, see the documentation article for using web APIs.
Constructors
JsonEndpoint(string, HttpMethod)
Initializes a new instance of JsonEndpoint<TParameters, TResult> with a relative URI and an optional HTTP method.
public JsonEndpoint(string relativeUri, HttpMethod method = null)
Parameters
relativeUri
stringA relative URI string for the current endpoint.
method
HttpMethodAn optional HTTP method.
Remarks
When setting the relative URI, avoid a leading forward-slash. Prefer myApp/doSomething
over /myApp/doSomething
.
If you omit the HTTP method, then the created builder will also not specify an HTTP method, which
(if used to generate a request) will result in an HTTP GET
request. See CreateRequestMessage().
JsonEndpoint(Uri, HttpMethod)
Initializes a new instance of JsonEndpoint<TParameters, TResult> with a URI and an optional HTTP method.
public JsonEndpoint(Uri uri, HttpMethod method = null)
Parameters
uri
UriA URI for the current endpoint; this may be relative or absolute.
method
HttpMethodAn optional HTTP method.
Remarks
If you omit the HTTP method, then the created builder will also not specify an HTTP method, which
(if used to generate a request) will result in an HTTP GET
request. See CreateRequestMessage().
Methods
GetHttpRequestMessageBuilder(TParameters)
Gets a HttpRequestMessageBuilder<TResponse> from the state of the current instance and the specified parameters value.
public override HttpRequestMessageBuilder<TResult> GetHttpRequestMessageBuilder(TParameters parameters)
Parameters
parameters
TParametersThe parameters required to create an HTTP request builder
Returns
- HttpRequestMessageBuilder<TResult>
An HTTP request message builder
Remarks
This method serializes the parameters
value into a JSON string and sets it into the HTTP request content:
Content.