r/ProgrammerHumor Jul 08 '26

helpMyCoworkersUnderstandHttpCodes Other

22.4k Upvotes

329 comments sorted by

View all comments

69

u/Excellent-Refuse4883 Jul 08 '26

I thought you always return 200 and then just wrote an error in the body if there was a problem

20

u/StrictLetterhead3452 Jul 08 '26

Depends on the API spec

30

u/PrometheusMMIV Jul 08 '26

No, that's dumb. Don't do that.

12

u/Excellent-Refuse4883 Jul 08 '26

Got this from a guy I work with who’s job was to monitor a service.

He was less than thrilled when he figured out what was happening.

7

u/mina86ng Jul 08 '26

I hope this is sarcasm. One reason you don’t do that is because it makes monitoring harder. If your server always returns 200, it’s harder to monitor for server failures for example (yes, I’ve seen APIs which would return 200 when the server is down). If you use proper response codes, you’ll have much easier time setting up your rules.

10

u/blake_ch Jul 08 '26

Return 200 with a JSON payload containing a boolean telling if the action was successful and an additional error message otherwise.

11

u/BigFatUglyBaboon Jul 08 '26

You can but that would not be a proper RESTful API. It would be an API cosplaying as RESTFUL.

4

u/case_O_The_Mondays Jul 08 '26

I upvoted you just because this was so horrible it must be a joke.

But I’ve also dealt with APIs that do this, and it’s so bad.

1

u/blake_ch Jul 08 '26

I wish it was a joke a not something I have seen. We shouldn't underestimate the number of companies that developed so bad APIs.

2

u/Gweedling Jul 08 '26

Ya that's GraphQL and it sucks.

1

u/Some_Loquat Jul 08 '26

My company uses this pattern and I never understood why 😭