Working with .net8.0 Blazor Web App with MinimalAPI and FastEndpoints. Currently, to send an object to a get request that returns a list I’m using
var req = new GetAgencyListRequest()
{
AgentLastName = _searchText,
AgencyName = _searchText
};
using (var httpSvc = new HttpService(state))
{
var request = new HttpRequestMessage
{
Method = HttpMethod.Get,
RequestUri = new Uri(httpSvc.BaseAddress + "agency/AgencyList"),
Content = new StringContent(JsonSerializer.Serialize(req), Encoding.UTF8,
"application/json")
};
var response = await httpSvc.SendAsync(request);
if (!response.IsSuccessStatusCode)
throw new Exception("Could not get Agency list");
using (var stream = response.Content.ReadAsStream())
{
var options = new JsonSerializerOptions { PropertyNameCaseInsensitive = true };
_gridData = JsonSerializer.Deserialize<List<Agency>>(stream, options);
}
}
This works, but it seems like it could be simplified. I found GetFromJsonAsAsyncEnumerable, but can’t find a way to send the request object. I could pass as parameters, but I have other more complex requests so I want to use this method.
var uri = new Uri("agency/AgencyList");
var resp = httpSvc.GetFromJsonAsAsyncEnumerable<Agency>(uri);
I can’t find a way to send the object.
How do I send an object with this method?
Thank you