Greg W
Greg W

Reputation: 91

GET vs. POST Json response and DTO

I am programming a C# Blazor Web application.

GET--- I typically communicate with my server side controllers using a GET if I wish a response that then deserializes into a C# object I can use client side. I use the URL append to send parameters to my controller from which to create the response to the GET.

POST--- I typically communicate with my controller using a POST if I wish to send back a Data Transfer Object for the server to do something with and all I wish is a response (i.e. success)

Presently though, I wish to use a DTO to send some serialized information back to the controller and want to receive a response that then deserializes into a C# object.

The issue I have is that the code below shows lines from two different httpclients of mine showing how I can put my 'obj' variable which is my DTO into a PostAsJsonAsync, however, the GetFromJsonAsync doesn't allow me to send an object over (note these two lines are in separate httpclients... just put together to show them). How do others accomplish the task of sending a DTO and receiving more than a simple Response Message back?

    var rtnJson = await _http.GetFromJsonAsync<List<ChartPoint>?>(requestUri.ToString(),token);
    var httpResponse= await _http.PostAsJsonAsync(requestUri, obj, token);

Upvotes: 0

Views: 120

Answers (1)

Greg W
Greg W

Reputation: 91

See comment above. The overload PostAsJsonAsync syntax allows return of a type specified by the controller.

Upvotes: 0

Related Questions