SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Wizard
    Join Date
    Jan 2005
    Location
    blahblahblah
    Posts
    1,447
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    API: which HTTP code should I use?

    Hello,

    Here's a situation I have a hard time sorting out. What code should you use when you receive a valid HTTP request but you can't process it because, say, a required parameter is missing? I would say a 200 (the HTTP request itself was well-formed and went fine) which returns an error message.

    I guess it's more complicated than that.

    I know that Github returns either a 400 or a 422, but that's if the request itself had a problem, right? http://developer.github.com/v3/

    Regards.

    -jj.

  2. #2
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    I believe by your description, 400 would be the correct header. A missing, required parameter is bad syntax.
    400 Bad Request
    The request cannot be fulfilled due to bad syntax.
    However, 422 could also be used.
    422 Unprocessable Entity
    The request was well-formed but was unable to be followed due to semantic errors.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  3. #3
    SitePoint Wizard
    Join Date
    Jan 2005
    Location
    blahblahblah
    Posts
    1,447
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thanks

    What if there is an error, say, with the database? Which code should it be?

  4. #4
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    500 Internal Server Error
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.



Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •