Quantcast
Channel: General Programming - MetaRuby - Ruby Forum
Viewing all articles
Browse latest Browse all 46

Use HTTP status codes with your APIs

$
0
0

@reggieb1 wrote:

Am I the only person to get annoyed when people don't use HTTP status codes when they build an API?

I'm working with an API at the moment. The API has been built using Rails, which is fine by me. However, I just posted some data and got the following:

response => <Net::HTTPOK 200 OK readbody=true>
response.body
 => "{\"status\":\"ERROR\",\"result\":\"failure\",\"message\":\"Lines.description can't be blank\"}"

What! The call has obviously failed. So why is the HTTP status code set to 200!

The response should have been a 400 Bad Request. If that was the case, I wouldn't have to dig around in the body of the response to determine whether the request had been successful or not.

The HTTP protocol has a host of HTTP status codes, for providing a rich vocabulary of responses to a request. It is so annoying when API developer/designers ignore that richness.

Posts: 8

Participants: 3

Read full topic


Viewing all articles
Browse latest Browse all 46

Trending Articles