Class MakeWebApiRequests
- Namespace
- CSF.Screenplay.WebApis
- Assembly
- CSF.Screenplay.WebApis.dll
An ability class which allows Actors to make HTTP web API requests using HttpClient.
public sealed class MakeWebApiRequests : IDisposable
- Inheritance
-
MakeWebApiRequests
- Implements
- Inherited Members
Properties
DefaultClient
Gets or sets the HTTP client, for scenarios in which the actor needs to use a single client.
public HttpClient DefaultClient { get; set; }
Property Value
Remarks
If the actor needs to know about more than one HTTP client, then consider using the indexer instead, which allows storage of more than one client, using arbitrary names.
this[string]
Gets or sets an HTTP client with a specified name.
public HttpClient this[string name] { get; set; }
Parameters
name
stringThe name of the HTTP client for which this instance is getting or setting.
Property Value
- HttpClient
An HTTP client associated with the specified name, or null reference if no HTTP client has been configured for that name.
Remarks
Use this indexer if an actor needs to manage more than one HTTP client. The key to this index - a name - is completely arbitrary and may mean whatever your needs require. Names must not be null and should not be empty or whitespace-only strings.
The name DefaultClient
is reserved for the value of DefaultClient. If the actor needs to use only a single
HTTP client then yoy may find the DefaultClient property easier to use, instead of this indexer.
Exceptions
- ArgumentNullException
If
name
is null.
Methods
AddClient(string, string)
Adds a new HTTP client to the current instance, with an optional base URI and client name.
public void AddClient(string baseUri = null, string clientName = null)
Parameters
baseUri
stringOptional, the base URI to which requests should be sent
clientName
stringOptional, the name of the client. If omitted then the new client will be the DefaultClient
Remarks
This method is a shorthand for adding a new item to either DefaultClient or the class indexer. It allows the convenient configuration of a new HttpClient with just a base URI to which requests should be sent.
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
GetClient(string)
Gets an HTTP client with the specified name.
public HttpClient GetClient(string clientName = null)
Parameters
clientName
stringAn optional client name, if omitted then the default client will be returned.
Returns
- HttpClient
An HTTP client
Remarks
If clientName
is null then the DefaultClient will be returned.
Exceptions
- InvalidOperationException
If
clientName
is specified & non-null but the current instance has no client of that name.