Class RestInterface
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 : IUrlProvider
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(RestClient, Nullable<IUrlProvider>)
Initializes a new instance of the RestInterface class whose full URL depends on another IUrlProvider.
Declaration
public RestInterface(RestClient restClient, IUrlProvider? baseUrlProvider = default(IUrlProvider? ))
Parameters
Type | Name | Description |
---|---|---|
RestClient | restClient | The RestClient which ultimately manages (or rather "contains") this interface. |
Nullable<IUrlProvider> | baseUrlProvider | An IUrlProvider which is the logical parent of this interface. The URL which is provided by this IUrlProvider is used as this interface's base url. If null, the |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
Properties
BaseUrlProvider
Gets 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.
Declaration
protected IUrlProvider BaseUrlProvider { get; }
Client
Gets the RestClient which ultimately manages (or rather "contains") this interface. This client's configuration is supposed to be used when building requests.
Declaration
protected RestClient Client { get; }
Url
Gets the URL which was built for the RestInterface.
Declaration
protected Uri Url { get; }
Methods
BuildRequest()
Returns a new ApiRequest instance which can be used to build a specific request against this interface.
The request is preconfigured with the default configuration of the Client and the URL of this interface which was created via BuildUrl(UrlBuilder).
Declaration
protected virtual ApiRequest BuildRequest()
Returns
Type | Description |
---|---|
ApiRequest | A new ApiRequestBase instance. |
BuildUrl(UrlBuilder)
Builds the full URL of this interface by using the specified UrlBuilder.
Declaration
protected abstract UrlBuilder BuildUrl(UrlBuilder baseUrl)
Parameters
Type | Name | Description |
---|---|---|
UrlBuilder | baseUrl | An UrlBuilder which was created by this interface's parent. This builder most likely holds some kind of base URL which can be extended with this interface's information. For example, the parent may already have configured the builder with a base URL
like |
Returns
Type | Description |
---|---|
UrlBuilder | The final UrlBuilder which holds the parts of this interface's URL.
This should usually be the incoming |
Explicit Interface Implementations
IUrlProvider.GetUrlBuilder()
Creates and returns a new UrlBuilder instance which is configured with this member's current URL information.
Declaration
UrlBuilder IUrlProvider.GetUrlBuilder()
Returns
Type | Description |
---|---|
UrlBuilder | A new UrlBuilder instance which is already configured with the URL information that this member has. |