❔ What should web api controller return?
I can return Ok with some json as parameter. Or I can return simple string
For example, I have method in controller:
Is it correct to return just a string?
9 Replies
it will work
the preferred return is
ActionResult<string>
ok, thanks!
a HTTP GET for an endpoint called "movies", I'd expect it to return an array/list of something
is is worth to serialize "movies" to json and than return Ok with it?
It'll serialise it automatically
On the reading end you'd do like
var movies = await httpClient.GetFromJsonAsync<List<Movie>>(URI);
ah ok, thanks
serialization is usually delegated to the framework, involved validation is usually not
the serialization format can be controlled with attributes
or filters in general
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.