| | | 1 | | using ArturRios.Util.Http; |
| | | 2 | | |
| | | 3 | | namespace ArturRios.Util.WebApi.Client; |
| | | 4 | | |
| | | 5 | | /// <summary>Base class for strongly-typed clients that call a single web API through an <see cref="HttpGateway"/>.</sum |
| | | 6 | | public abstract class BaseWebApiClient |
| | | 7 | | { |
| | | 8 | | /// <summary>The HTTP gateway used to issue requests to the target API.</summary> |
| | | 9 | | protected readonly HttpGateway Gateway; |
| | | 10 | | |
| | | 11 | | /// <summary>Initializes the client from an existing <see cref="HttpClient"/> and lets the derived class configure i |
| | | 12 | | /// <param name="httpClient">The HTTP client to wrap.</param> |
| | 0 | 13 | | protected BaseWebApiClient(HttpClient httpClient) |
| | 0 | 14 | | { |
| | 0 | 15 | | Gateway = new HttpGateway(httpClient); |
| | | 16 | | |
| | 0 | 17 | | SetRoutes(); |
| | 0 | 18 | | } |
| | | 19 | | |
| | | 20 | | /// <summary>Initializes the client with a new <see cref="HttpClient"/> pointed at <paramref name="baseUrl"/> and le |
| | | 21 | | /// <param name="baseUrl">The base address of the target API.</param> |
| | 0 | 22 | | protected BaseWebApiClient(string baseUrl) |
| | 0 | 23 | | { |
| | 0 | 24 | | var httpClient = new HttpClient { BaseAddress = new Uri(baseUrl) }; |
| | | 25 | | |
| | 0 | 26 | | Gateway = new HttpGateway(httpClient); |
| | | 27 | | |
| | 0 | 28 | | SetRoutes(); |
| | 0 | 29 | | } |
| | | 30 | | |
| | | 31 | | /// <summary>Configures the routes (endpoints) exposed by this client. Called once during construction.</summary> |
| | | 32 | | protected abstract void SetRoutes(); |
| | | 33 | | } |