yossi
yossi

Reputation: 13315

REST API request failed http response code

I am implementing a REST API and i have a set_ftp_credentials request for example

POST api.domain.com/object/set_ftp_credentials

This request checks that the ftp credentials are good by trying to connect.
We had a discussion here whether we should return a HTTP response 200 and in the content
return the the request have failed and the reason.
Or we should return some other HTTP response code (40* response code).

What is considered the right way of doing this ?

And if not 200 then what do you think is the right response code ?

Upvotes: 0

Views: 8582

Answers (2)

Raghav Boorgapally
Raghav Boorgapally

Reputation: 412

One approach would be to answer the following questions for yourself:

  1. What HTTP methods are you supporting?
  2. What is the expected behavior of each HTTP method?
  3. For each supported HTTP method, What are the possible classes of failures that can result if something goes wrong?

Now, return your expected response pay load with a 200 HTTP response code. Return client side error (400 class) or server side error (500 class) for the failures.

You might want to consider the following:

  • Return error codes that are specific to your application and map them to HTTP error codes
  • Have separate data contracts (assuming JSON format or XML schema) defined for successful response and error responses

Upvotes: 2

Vasisualiy
Vasisualiy

Reputation: 750

I believe that 200 is an OK response and should only be sent when the request was successfully satisfied.

Upvotes: 3

Related Questions