Simple POST request with a JSON body and response type

This sends an HTTP POST request to the Reqres api which is a fake online REST api that includes a generic /api/<resource> route that responds to POST requests for any <resource> with the contents of the post body and a dynamic id property. This example sends a new article in the postBody to the /api/articles route and then converts the response to an Article object and assigns it to the blazor component property article so it can be displayed in the component template.

private Article article;

protected override async Task OnInitializedAsync()
{
    var postBody = new { Title = "Blazor POST Request Example" };
    using var response = await HttpClient.PostAsJsonAsync("https://reqres.in/api/articles", postBody);

    // convert response data to Article object
    article = await response.Content.ReadFromJsonAsync<Article>();
}

#webassembly

Blazor WebAssembly - HTTP POST Request Examples
35.05 GEEK