Blazor Support for Rest API

Any news on REST Api support in Blazor ?

Regards

This can currently be done using Invoke method action.

I uploaded a new example in the Github repository. It shows how to use a REST API (the GitHub issues API). The important code is in the GithubIssues.razor.cs file.

  public class GitHubIssue
  {
    [JsonPropertyName("html_url")]
    public string Url { get; set; }

    public string Title { get; set; }

    [JsonPropertyName("created_at")]
    public DateTime Created { get; set; }
  }

  public partial class GithubIssuesComponent
  {
    [Inject]
    public HttpClient HttpClient { get; set; }

    public async Task<IEnumerable<GitHubIssue>> GetIssues(string repo)
    {
      var message = new HttpRequestMessage(HttpMethod.Get, $"https://api.github.com/repos/{repo}/issues?state=open&sort=created&direction=desc");
      message.Headers.Add("Accept", "application/vnd.github.v3+json");
      message.Headers.Add("User-Agent", "HttpClient");

      var response = await HttpClient.SendAsync(message);

      response.EnsureSuccessStatusCode();

      var json = await response.Content.ReadAsStringAsync();

      return JsonSerializer.Deserialize<IEnumerable<GitHubIssue>>(json, new JsonSerializerOptions
      {
        PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
        PropertyNameCaseInsensitive = true,
      });
    }
  }

In Radzen you need to specify the method and invoke it.

Are you still planning on having a similar experience for Rest API's as you have with your Angular implementation?

Yes, REST data sources will be supported in Radzen blazor applications. In fact it is one of the next items we plan to work on!

1 Like