Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Best Practice: HTTP Status Codes

Not applicable

I have a service which returns students, by locker number. Depending on the query, my service may return:

  • One student
  • Multiple students (meaning the locker is shared & you should probably provide a locker-shelf number as well)
  • No student
  • Error processing your request (bad locker number?)

I've seen some APIs leverage the HTTP status codes to communicate resource state. Eg:
20x for 'one student'
30x for 'multiple students'
40x for 'no student'
50x for 'error'

Do modern developers expect this? Or.. should status codes speak only to the HTTP response state, rather than hinting at payload? I'm looking for some pros/cons, based on what you've seen work for other successful API programs.

1 9 2,653
9 REPLIES 9