Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Should a REST API return exception in response body?

Should a REST API return exception in response body?

Scheduled Pinned Locked Moved ASP.NET
rubyjsoncsharpquestioncollaboration
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Bastien Vandamme
    wrote on last edited by
    #1

    What is the best practice in .NET with Web API? Especially Web REST API. Should a REST API return exception in response body when an exception happens? For sure I will return a 500 or similar HTTP status. But when I response with this error code what are the best practice? Or even better what is the specification or REST API about this? - return the exception (what I do) - return en empty response body? - return an empty of default JSON object? - something else? FYI I'm working on a Web pragmatic REST API in C# .NET that is consumed by a Ruby on Rails team and I'm not sure Ruby code can handle these exception message easily.

    J 1 Reply Last reply
    0
    • B Bastien Vandamme

      What is the best practice in .NET with Web API? Especially Web REST API. Should a REST API return exception in response body when an exception happens? For sure I will return a 500 or similar HTTP status. But when I response with this error code what are the best practice? Or even better what is the specification or REST API about this? - return the exception (what I do) - return en empty response body? - return an empty of default JSON object? - something else? FYI I'm working on a Web pragmatic REST API in C# .NET that is consumed by a Ruby on Rails team and I'm not sure Ruby code can handle these exception message easily.

      J Offline
      J Offline
      John C Rayan
      wrote on last edited by
      #2

      WEB API should return status code in the header and any content in the body. For example, if the request is successful then set the status code to 200 in the header and send the result in the body. If the request is failed , then set the corresponding status code in the header ( for example 500 etc...) and send additional information in the body.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups