-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Add some WebAPI-like action results/helpers to Controller #1378
Comments
Let's discuss BadRequest(ModelState) as part of #1377 |
Depends on outcome of discussion from #657. |
Recommendation for the scope of this item:Enhancements to ObjectResult
BadRequest()
Created(string location, object content)
CreatedAtAction(...)
CreatedAtRoute(...)
|
Not sure if this should be separate, but please also add a helper for HttpUnprocessableEntity (422). See
|
@DamianEdwards there are the helpers we plan to add to the controller for API scenarios (other than improving the pattern), if there is anything missing please add here. @ashmind we are not planning to add support for (422) in a helper, and we do not own the |
I realize this, that's why I ask for a helper and not for an enum entry.
By this logic 422 is a more useful helper than 400. 400 is a malformed request, which should not really happen after you got inside the controller action (handled by ModelBinders/MediaFormatters etc). 422 is most of semantic validation, which is pretty common inside controller actions. |
400 is what you return when you get model errors, so you are already in the controller. Like I mentioned above the helper method is trivial to write, is purely additive and we would like to keep the controller api surface minimal, as its already pretty large. We can take a second look, and if we change our mind we will post here. |
@ashmind Thanks for the samples. Reading the RFC, it is still a big ambiguous when it comes to invalid data in the query (or the url for that matter), but I do see your point. I suggest you open a separate issue, and we can follow up on this specifically. |
We could do with a few enhancements for API scenarios using
Controller
. Some ideas shamelessly stolen from WebAPI.BadRequest()
- 400BadRequest(string)
- 400 with a conneg error object (see Add HttpError or similar type to Core #1377)BadRequest(ModelState)
- 400 with a conneg error object with model errors (see Add HttpError or similar type to Core #1377)Created(string location, object content)
- 201 with conneg contentCreatedAtAction(...)
- 201 with conneg contentCreatedAtRoute(...)
- 201 with conneg contentThere are more of these action result methods in
ApiController
but these seem like the useful ones that are gaps in the core framework.The text was updated successfully, but these errors were encountered: