1

I am creating a simple API to validate a membership. Client will have to input a String ID and Server will check if the ID is a valid member of our, lets say, community. The ID must be numeric only, with length 10.

Quite simple right?

If the ID is a valid, of course we will return HTTP Status Code OK. If the ID is contains alfabet, or less/more than 10, then we will return HTTP Status Code BAD REQUEST.

The question is, what is the best practive HTTP Status Code to return when the ID is numeric and length = 10, but is NOT a member of our community? and why is that.

Silly Sally
  • 1,027
  • 2
  • 10
  • 15
  • Well II don't know if it's a best practice but I'd return HTTP status code NOT_FOUND (404) because all validation checks have been passed but no record with that ID is found in your community – Angelo Immediata Jan 18 '17 at 11:55

1 Answers1

0

The endpoints of a REST API are normally resources on which you act using HTTP methods like GET,PUT,POST,DELTE. When you do it like that, its much easier to decide which HTTP status to return.

So may be you could make an endpoint

/member/{id}
  • if a member with this id exists, return HTTP 200 and if you want some JSON with basic member info
  • if the id is valid, but no member exists, return HTTP 404 - NOT FOUND
  • if the id is not valid, length !=10 or contains invalid chars, return a HTTP 400 BAD REQUEST

Here you can find more about REST API design