Extension methods to simplify common HttpClientExtension such as working with JSON.
More...
|
static Task< TResponse > | GetAsJsonAsync< TResponse > (this HttpClient httpClient, Uri uri, int? maxCharactersToPrint=null) |
| GETs the given address, and serializes the resulting JSON object into an object of type T. Throws an error on non-2xx status messages. More...
|
|
static async Task< TResponse > | GetAsJsonAsync< TResponse > (this HttpClient httpClient, string url, int? maxCharactersToPrint=null) |
| GETs the given address, and serializes the resulting JSON object into an object of type T. Throws an error on non-2xx status messages. The response is expected to be a JSON body and is serialized to TResponse . More...
|
|
static Task< TResponse > | PostAsJsonAsync< TResponse > (this HttpClient httpClient, Uri uri, object? jsonBody=null, int? maxCharactersToPrint=null) |
| POSTS to the uri , with a potentially provided jsonBody . The response is expected to be a JSON body and is serialized to TResponse . More...
|
|
static async Task< TResponse > | PostAsJsonAsync< TResponse > (this HttpClient httpClient, string url, object? jsonBody=null, int? maxCharactersToPrint=null) |
| POSTS to the url , with a potentially provided jsonBody . The response is expected to be a JSON body and is serialized to TResponse . More...
|
|
Extension methods to simplify common HttpClientExtension such as working with JSON.
◆ GetAsJsonAsync< TResponse >() [1/2]
static async Task<TResponse> GetAsJsonAsync< TResponse > |
( |
this HttpClient |
httpClient, |
|
|
string |
url, |
|
|
int? |
maxCharactersToPrint = null |
|
) |
| |
|
inlinestatic |
GETs the given address, and serializes the resulting JSON object into an object of type T. Throws an error on non-2xx status messages. The response is expected to be a JSON body and is serialized to TResponse .
- Parameters
-
httpClient | HttpClient to use. |
url | The URL to GET. This url has the same semantics as when using the regular "GetAsync" in regards to respecting BaseAddress. |
maxCharactersToPrint | If any errors occurs, how many characters of the response body should be included in the response body? If set to null, records the entire response. |
- Template Parameters
-
TResponse | The type to attempt to serialize the JSON response to. |
- Returns
- The response from the server as TResponse .
◆ GetAsJsonAsync< TResponse >() [2/2]
static Task<TResponse> GetAsJsonAsync< TResponse > |
( |
this HttpClient |
httpClient, |
|
|
Uri |
uri, |
|
|
int? |
maxCharactersToPrint = null |
|
) |
| |
|
inlinestatic |
GETs the given address, and serializes the resulting JSON object into an object of type T. Throws an error on non-2xx status messages.
- Parameters
-
httpClient | HttpClient to use. |
uri | The URI to GET. Note that this needs to be a fully qualified URI starting with http(s): Any BaseAddress from the HttpClient is not respected. |
maxCharactersToPrint | If any errors occurs, how many characters of the response body should be included in the response body? If set to null, records the entire response. |
- Template Parameters
-
TResponse | The type to attempt to serialize the JSON response to. |
- Returns
- The response from the server as TResponse .
◆ PostAsJsonAsync< TResponse >() [1/2]
static async Task<TResponse> PostAsJsonAsync< TResponse > |
( |
this HttpClient |
httpClient, |
|
|
string |
url, |
|
|
object? |
jsonBody = null , |
|
|
int? |
maxCharactersToPrint = null |
|
) |
| |
|
inlinestatic |
POSTS to the url , with a potentially provided jsonBody . The response is expected to be a JSON body and is serialized to TResponse .
- Parameters
-
httpClient | The HttpClient to use for the operation. |
url | The URL to POST to. This url has the same semantics as when using the regular "postAsync" in regards to respecting BaseAddress. |
jsonBody | The object to be serialized to JSON and included in the body. If not specified or null, no body will be sent. |
maxCharactersToPrint | If an error happen, how many characters of the HTTP response to include in the exception message. If not provided, will record the entire response. |
- Exceptions
-
HttpRequestException | Will throw HttpRequestException if server responds with non-2xx status code. |
JsonException | Will throw JsonException if it was unable to parse the response body to TResponse . |
- Template Parameters
-
TResponse | The response type to parse the returned JSON to. |
- Returns
- The response type serialized into TResponse .
◆ PostAsJsonAsync< TResponse >() [2/2]
static Task<TResponse> PostAsJsonAsync< TResponse > |
( |
this HttpClient |
httpClient, |
|
|
Uri |
uri, |
|
|
object? |
jsonBody = null , |
|
|
int? |
maxCharactersToPrint = null |
|
) |
| |
|
inlinestatic |
POSTS to the uri , with a potentially provided jsonBody . The response is expected to be a JSON body and is serialized to TResponse .
- Parameters
-
httpClient | The HttpClient to use for the operation. |
uri | The URI to POST to. Note that this needs to be a fully qualified URI starting with http(s): Any BaseAddress from the HttpClient is not respected. |
jsonBody | The object to be serialized to JSON and included in the body. If not specified or null, no body will be sent. |
maxCharactersToPrint | If an error happen, how many characters of the HTTP response to include in the exception message. If not provided, will record the entire response. |
- Exceptions
-
HttpRequestException | Will throw HttpRequestException if server responds with non-2xx status code. |
JsonException | Will throw JsonException if it was unable to parse the response body to TResponse . |
- Template Parameters
-
TResponse | The response type to parse the returned JSON to. |
- Returns
- The response type serialized into TResponse .
The documentation for this class was generated from the following file: