Welcome to Shaun Luttin's public notebook. It contains rough, practical notes. The guiding idea is that, despite what marketing tells us, there are no experts at anything. Sharing our half-baked ideas helps everyone. We're all just muddling thru. Find out more about our work at bigfont.ca.

IHttpActionResult Shortcut Methods

Tags: http, web-development, asp.net, web-api

The ApiController in Web API 2 has action methods that return an IHttpActionResult interface. There ApiController class has shortcut methods for creating certain results. From within an Action Method, we can call any other following methods that are associated with certain HTTP status codes:

  • BadRequest()
    • 400 Bad Request
  • Conflict()
    • 409 Conflict
  • Created()
    • 201 Created
  • Ok()
    • 200 OK
  • InternalServerError()
    • 500 Internal Server Error
  • JSON()
    • 200 OK
  • Redirect()
    • 302 Found
  • StatusCode()
    • Any
  • Unauthorized()
    • 401 Unauthorized
  • NotFound()
    • 404 Not Found

See also

http://msdn.microsoft.com/en-us/library/system.web.http.apicontroller_methods%28v=vs.118%29.aspx

http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html