This extension provides constants and extension methods frequently used while developing Azure Functions apps.
The following constants represent the string respectively.
It specifies the content type.
ContentTypes.PlainText
:text/plain
ContentTypes.TextHtml
:text/html
ContentTypes.ApplicationJson
:application/json
ContentTypes.TextVndYaml
:text/vnd.yaml
It specifies the HTTP method.
HttpVerbs.GET
:GET
HttpVerbs.POST
:POST
HttpVerbs.PUT
:PUT
HttpVerbs.PATCH
:PATCH
HttpVerbs.DELETE
:DELETE
It specifies whether the HTTP request comes from.
Header
: Request source comes from the request header.Query
: Request source comes from the request querystring.Body
: Request source comes from the request body.
It extracts relevant data from the given source of the HTTP request.
public async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, HttpVerbs.GET)] HttpRequest req)
{
var headers = await req.To<IHeaderDictionary>(SourceFrom.Header)
.ConfigureAwait(false);
var queries = await req.To<IQueryCollection>(SourceFrom.Query)
.ConfigureAwait(false);
var payload = await req.To<MyClass>(SourceFrom.Body)
.ConfigureAwait(false);
...
}
It returns the content type based on the OpenAPI document format.
var format = OpenApiFormat.Json;
var contentType = format.GetContentType();
It serialises the given payload to JSON string.
var payload = new MyClass() { Message = "hello world" };
var serialised = payload.ToJson();
It deserialises the JSON string value to given type.
var payload = "{ \"message\": \"hello world\" }"
var deserialised = payload.FromJson<MyClass>(payload);