This repository has been archived by the owner on Feb 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
HttpRequest extensions
Fernando Escolar edited this page May 6, 2021
·
1 revision
These are the methods to extend the HttpRequest
behavior:
Task<T> FromJsonAsync<T>(bool validateMediaType = false, CancellationToken cancellationToken = default);
T FromRoute<T>(string name);
T FromQuery<T>(string name);
bool TryFromRoute<T>(string name, out T result);
bool TryFromQuery<T>(string name, out T result);
-
FromJsonAsync: Deserializes the request body using
System.Text.json.JsonSerializer
. IfvalidateMediaType
is set totrue
it throws an exception when the media type of the request it's not "application/json". If you don't specifycancellationToken
it uses the currentHttpContext.RequestAborted
value. - FromRoute: Gets a value from the request route values.
- FromQuery: Gets a value from the request query string values.
-
TryFromRoute: Tries to get a value from the request route values. Returns
false
if it doesn't exists. -
TryFromQuery: Tries to get a value from the request query string values. Returns
false
if it doesn't exists.