Class RestInterface<TClient>
Defines a base class for wrapping an interface of a RESTful HTTP API and exposing the HTTP requests which can be made against that interface. See remarks for details on what an interface means in this context.
Implements
Namespace: ReqRest
Assembly: ReqRest.dll
Syntax
public abstract class RestInterface<TClient> : RestInterface, IUrlProvider where TClient : RestClient
Type Parameters
Name | Description |
---|---|
TClient | A specific RestClient type which is associated with this interface. Specify this type parameter if you need to access specific properties from your custom client implementation via this class' Client property. |
Remarks
An interface in the context of this library means a certain part of an URL which identifies a resource in a RESTful API.
For example, given the http://api.com/todos
URL, the todos
part is
an interface.
If a RestClient is configured with the base URL of that API (i.e.
(http://api.com
), this base URL can be combined with the interface part
todos
to form a full URL.
It is important to understand that ReqRest maps each possible interface to one class.
For example, while the two URLS http://api.com/todos
and http://api.com/todos/123
might look like one interface, they are actually treated as two RestInterface
members by ReqRest.
This is because the two URLs support different methods. While the first one usually
supports methods like GET
and POST
, the second one usually supports
GET
, POST
, PUT
and DELETE
.
Thus, it makes sense to separate them into different classes that make different
requests available.
Constructors
RestInterface(TClient, Nullable<IUrlProvider>)
Initializes a new instance of the RestInterface class whose full URL depends on another IUrlProvider.
Declaration
public RestInterface(TClient client, IUrlProvider? baseUrlProvider = default(IUrlProvider? ))
Parameters
Type | Name | Description |
---|---|---|
TClient | client | The |
Nullable<IUrlProvider> | baseUrlProvider | An IUrlProvider which is the logical parent of this interface. The URL which is returned by this IUrlProvider is used as this interface's base url. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
Properties
Client
Gets the TClient
which ultimately manages (or rather "contains")
this interface.
This client's configuration is supposed to be used when building requests.
Declaration
protected TClient Client { get; }