Use Refit for APIs, make data/API stack async
This commit is contained in:
parent
9c4f01ab13
commit
b00158daa7
17 changed files with 196 additions and 124 deletions
|
|
@ -1,6 +1,8 @@
|
|||
@using Start.Shared
|
||||
@using System.IO
|
||||
@inject HttpClient Http
|
||||
@using Start.Shared.Api
|
||||
@using Refit
|
||||
|
||||
@inject IBookmarkContainersApi bookmarkContainersApi
|
||||
|
||||
<Dialog Title="Create Container" Active="this.IsOpen" OnClose="this.OnDialogClose">
|
||||
<EditForm Model="this.model" OnValidSubmit="this.OnSubmit">
|
||||
|
|
@ -50,16 +52,10 @@
|
|||
|
||||
protected async void OnSubmit()
|
||||
{
|
||||
HttpResponseMessage response = await Http
|
||||
.PostAsJsonAsync("BookmarkContainers/Create", model.Title);
|
||||
ApiResponse<BookmarkContainerDto?> apiResponse = await bookmarkContainersApi
|
||||
.CreateBookmarkContainer(model.Title);
|
||||
|
||||
Stream stream = response.RequestMessage!.Content!.ReadAsStream();
|
||||
StreamReader reader = new StreamReader(stream);
|
||||
Console.WriteLine(reader.ReadToEnd());
|
||||
|
||||
BookmarkContainerDto? container = await response
|
||||
!.Content
|
||||
!.ReadFromJsonAsync<BookmarkContainerDto>();
|
||||
BookmarkContainerDto? container = apiResponse.Content;
|
||||
|
||||
if (container == null)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication
|
||||
@using Start.Shared.Api
|
||||
|
||||
@inject HttpClient Http
|
||||
@inject IBookmarkContainersApi bookmarkContainersApi
|
||||
|
||||
@{ string title = $"Delete Container \"{this.ContainerTitle}\""; }
|
||||
|
||||
|
|
@ -41,8 +44,8 @@
|
|||
{
|
||||
try
|
||||
{
|
||||
HttpResponseMessage result = await Http
|
||||
.DeleteAsync($"BookmarkContainers/Delete/{this.BookmarkContainerId}");
|
||||
HttpResponseMessage result = await bookmarkContainersApi
|
||||
.DeleteBookmarkContainer(this.BookmarkContainerId);
|
||||
|
||||
if (result.StatusCode == System.Net.HttpStatusCode.OK)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue