Same. It’s either POST or GET (for readahead queries. Because my boss insists that the user be able to type and select from a drop down, so that’s the best compromise I can come up with).
Error code? On error you just get 200 with either an empty body or even better, a guessed fallback value that will fail 6 systems down the road. The error is logged with info level (everything is info) in a log the developers can‘t access for compliance reasons.
you don't want silly pictures layer of front end to have any of that tough big boy logic like error handling to worry their pretty little frames about, it have to focus on rendering same square button with shade 60 frames a second ;^( it's for security, or something
On error return 200 with payload {status:error, value: math.round(Math.random()*10000,0)}, the actual error goes into a log that is accessed through its on errorApi
Write that fact in the documentation and if ever anybody complains, tell them to rtfm
Very few things in software dev shit me more than this. It means every type has to be a union of success and failure and defensive checks everywhere, rather than catching errors/exceptions.
I mean checking for errors is implicitly making the type a union of success and failures already, the problem is that you already have that wrapper, so why then put the errors inside the success type?? Insanity!
Oh you didnt know if you could you were just saying it as a hyperbole? Ill check then. Im a fan of goto statements so I would use them if there were ones
I'd really rather have the error checking at a level above the browser. I don't want to deal with 400 or 500 error codes clogging up the debugging console. In typescript/nextjs this is a fairly easy thing as the return types can be set to include error messages or success messages. Problem solved.
I don't want a 404 from an API that exists because that allows backwards compatibility, since 404 is what I get for an API that doesn't exist. If I get a 404 I can fall back to an older API for instance.
I'm perfectly happy with an API returning 200 and some JSON with "user doesn't exist".
But it doesnt exist. That’s the point. It’s a Uniform RESOURCE Locator. The RESOURCE (user) does not exist. The URL is invalid. Just because there are other resources with a similar-but-different path doesn’t matter.
You’re confused and not understanding the words. It “doesn’t have an API” when the resource does t exist. 404 does NOT mean the route is incorrect. It means the RESOURCE was not found. It is a client side “you fucked up, try again the right way” error.
It sounds like you’re using 404 to determine if you’ve even got the right server, which is nutty. How do you not know what server/api path you’re supposed to be calling? How are you even sending not existing data to the API.
In the user example 1234 doesn’t exist. Where’d you even get that from that you think that’s valid?
Yes! If an API returns structured data it can tell me anything, including "user doesn't exist". I want to be able to distinguish that from hitting a server that doesn't have the API. Otherwise I have to attempt to parse the response as JSON, and if it fails to parse or doesn't match the expected format, then assume the API isn't present and fall back to something else. I've had to do that and it's not pleasant.
I'll have to trust you about a good chunk of REST logic being related to HTTP codes (I only wrote simple client code), but again my use case is version compatibility, so an agreed upon API is not possible without a version check. Which I suppose is possible to do, but that adds complexity plus latency on the "happy path".
Latency? wtf are you talking about. There’s many common ways to request a specific version.. url path (/api/v1/user), send it in the header, different host and, etc etc. if that’s adding significant latency you’re doing something very wrong.
I never realised why people did this until I was 5 year into my job.
There are errors that are known and errors that are not known. Distinguishing them is actually really important in most scenarios. Is there a better way to do this than passing back 200? yes but I can see why people do this.
What do you mean errors that are known or not know? Do you have examples? In any case it's either a client or server error, so at least use 400 or 500.
I think that isn't that bad. Makes it way easier to write the frontend api for it. Usually http is just the protocol you build your own protocol on. If you get an http error you known directly that it is just a just a http error cause the endpoint doesn't exist or something else http related failed
I feel like this can swing too far in the other direction, and I've worked with APIs that returned a 404 even though the request was valid, the resource was correct, but a specific data point just couldn't be found.
Imagine troubleshooting a failed call and asking yourself "was this valid and the account wasn't found? Or did the path change? Or did the subdomain change?" with no extra information!
Ooh my company does this. We then noticed that status codes would be useful and introduced status which has to be there in each json packet. Then the app handled one specific status code in a way that was wanted for basically all responses so we always use that status code and added statusmessage, which is a string but works basically like a statuscode. It’s disgusting in a way words cannot describe.
I worked somewhere that did exactly that. The rationale was that they didn't trust the API users to know what they actually needed or to RTFM, so we just sorted it out on the back end. In that light, it made a little more sense...
"Always has been." Show me the HTTP spec for Patch or other REST specific methods. Although most http servers these days do include it, the rest of the infrastructure that relies on but doesn't implement may just use a base reference.
The concept of REST and the realities of infrastructure almost never line up, bu t POST always works.
How many REST purists had meetings (that could have been an email) with Ops to make sure their api specific crap can successfully navigate the ever growing maze of WAFs, proxies and LBs?
Since you asked for it so nicely, PATCH is defined in RFC 5789 and not superseeded by RFC 9110, which contains all the other methods. We can argue about PATCH being legit, but all the other "crap" is part of the standard HTTP spec.
GET i understand for purposes of retrieving serverside resources. But I don't understand why, for example, DELETE needs to exist. You're going to have way more verbs than there are HTTP verbs. So why not just have POSTs and encode everything in the query anyway?
>But I don't understand why, for example, DELETE needs to exist
To, I don’t know, DELETE resources…
>So why not just have POSTs and encode everything in the query anyway?
Because DELETE exists? It’s for deleting resources. When you say ‘encode everything in the query’ do you mean the URL? cause that would be a GET. You don’t really use query parameter with POST since you’re sending a body.
I can code 15 endpoints, 5 of which are the basic html actions, the other 10 of which are basically posts with the verb encoded in the body, or I can just skip the middle steps and do all 15 as a post. You see what I mean? Its usually way more difficult and confusing to make a bunch of handlers for POST, DELETE, UPDATE, GET etc than it is to make one and put the handling logic in the function
No I don’t see what you mean. The verb doesn’t go in the body. It’s part of the headers to the server, quite literally the first command sent to the server is VERB /path Whatever
Whatever you’re doing, you’re doing it the wrong. There’s no more effort in declaring DELETE or PATCH over POST.
Yeah I have to "code" in a "low code" environment for work and they didn't even implement anything besides GET and POST. And GET is often too erratic in their system. It also returns an API failure if the return values aren't exactly as the system expects, even if the API returned 200. All we get back is a success or fail so it's not like we could actually read an error. We have to go to the far sides developers and ask them what the result of our test was. It's a nightmare. Once it works, never touch it.
to be fair this is because the standard stupidly limits the others in various ways. for instance you can't send a body in a get request (some libs allow this, but it's non-standard and non-portable)
I seriously never understood why someone would do this...whats so difficult about using the other, fitting methods?? When I write API Routes, I mark the Method that is suitable, by the fuck would I use POST on a Delete Function?
If you're receiving information from the server you use GET, if you're sending information to the server you use POST, all the rest is fluff designed to overcomplicate things
I'm working with an API that only has posts. Everything is a post. This means a separate endpoint for every crud operation of every object. CreateCustomer, UpdateCustomer, DeleteCustomer, GetCustomer. All posts. It's such a dumb API it even goes further. There's shit like UpdateCustomerPhoneNumber.
It makes me want to quit my job, get hired by them and fix their API, quit that job and then become a beet farmer.
I am not a programmer, but they have now introduced REST based approach to diagnostics for vehicle ECUs. So now it expands to "is starting radar calibration PUT or POST?" or "Is deleting fault memory PUT or POST?" (it is not "DELETE" since the fault codes are not coming from a "PUT" and deleting itself is a diagnostic routine rather than "just deleting data").
because that's the right way to handle it when you're not working at http level (or with dumb rest)
Reading the comments I feel so safe in my job x) as long as most people do not even understand why you should NOT use anything else than POST, there will be shitty legacy to remake :D
I legit make my personal project app api post only... Is there actually a drawback? seems to be working fine without issues and makes the api more straightfoward to use
I wouldn't keep me up at night but following conventions is nice and it can have utility.
Say for example your API has one url for all of the stuff you do with POST. DELETE, PUT, etc can have completely different handlers and validation on that same url which is a nice clean implementation.
It's bad hygiene in personal apps because it has benefits in commercial apps. E.g. GETs get cached more aggressively on internet infrastructure. QUERYs will too.
159
u/PatienceLost9708 19d ago
the other methods are just for the technical interview
27
u/GigaGollum 19d ago
Replace HEAD with QUERY pls
5
u/Effective-Bill-2589 18d ago
I'm guilty of this
869
u/SirChasm 19d ago
You can do the reverse one with all responses being status 200 and you have to look inside to see what the error code
83
u/FallenVampireLord 19d ago
Same thing my wife told me
70
u/falcon0041 19d ago
Passing a body in GET was a terrible mistake I made long time back
195
u/jabrwock1 19d ago
Post but you have to parse it to figure out what operation they want to do. FML
33
u/Curious_Associate904 18d ago
There's a new one "QUERY" which is supposed to stop you doing this...
But, will you ever use it?
Be honest.
31
u/KevBurnsJr 19d ago
Because it has the fewest restrictions. No safety. No idempotency. It is the lowest common denominator.
11
u/TundraGon 18d ago
Anything's a POST if you argue long enough.
10
u/SilverBullet78SB 19d ago
POST:/api/update_user POST:/api/delete_user POST:/api/new_user My first days of learning HTTP
7
u/Mad-chuska 19d ago
Didn’t they just make a new method exactly for this?
21
u/granadesnhorseshoes 18d ago
"Always has been." Show me the HTTP spec for Patch or other REST specific methods. Although most http servers these days do include it, the rest of the infrastructure that relies on but doesn't implement may just use a base reference.
The concept of REST and the realities of infrastructure almost never line up, bu t POST always works.
How many REST purists had meetings (that could have been an email) with Ops to make sure their api specific crap can successfully navigate the ever growing maze of WAFs, proxies and LBs?
But POST always works.
10
u/Kuzame 18d ago
She would like to have a word with you..
5
u/kratz9 19d ago
Anyone remember WebDAV?
9
u/overclockedslinky 18d ago
to be fair this is because the standard stupidly limits the others in various ways. for instance you can't send a body in a get request (some libs allow this, but it's non-standard and non-portable)
3
u/Kitchen_Affect7369 18d ago
Where is GET? And use GET for post data?
3
u/torftorf 18d ago
I recently looked at an api documentation for a service my company uses. Every single endpoint is post. Even the ones called "get...."
2
u/distortedsignal 19d ago
Have you ever tried to write a PATCH API? It's wild...
2
u/NexusDarkshade 18d ago
Favorite thing (I lie): required to use POST request because GET query string is "too long"
2
u/migarma 18d ago
Normally for me, add things, POST; modify things, PUT; get things, GET; remove things, DELETE
2
u/No-Magazine-2739 18d ago
I am REST fan and cry like the girl that is famous for her reaction to this video
2
u/DrTight 18d ago
We have everything as POST and GET /deleteUser Horrible API
2
u/TrackLabs 18d ago
I seriously never understood why someone would do this...whats so difficult about using the other, fitting methods?? When I write API Routes, I mark the Method that is suitable, by the fuck would I use POST on a Delete Function?
2
u/xgabipandax 18d ago
If you're receiving information from the server you use GET, if you're sending information to the server you use POST, all the rest is fluff designed to overcomplicate things
2
u/FoxedDev 18d ago
IT'S QUERY TIME
2
u/atehrani 18d ago
GraphQL
2
u/tehtris 17d ago
I'm working with an API that only has posts. Everything is a post. This means a separate endpoint for every crud operation of every object. CreateCustomer, UpdateCustomer, DeleteCustomer, GetCustomer. All posts. It's such a dumb API it even goes further. There's shit like UpdateCustomerPhoneNumber.
It makes me want to quit my job, get hired by them and fix their API, quit that job and then become a beet farmer.
3
u/Tackgnol 18d ago
At one of my clients Akamai blocked Patch and Put xD.
So this was company policy.
2
u/Puzzleheaded-Weird66 19d ago
html5 forms only have post and get (on asp .net at least)
2
u/Honest_Relation4095 18d ago
I am not a programmer, but they have now introduced REST based approach to diagnostics for vehicle ECUs. So now it expands to "is starting radar calibration PUT or POST?" or "Is deleting fault memory PUT or POST?" (it is not "DELETE" since the fault codes are not coming from a "PUT" and deleting itself is a diagnostic routine rather than "just deleting data").
1
u/arran4 18d ago
It should all be PUT.
1
u/Ravens_Quote 18d ago
So no head?
1
u/icedamericaono 18d ago
https://imgflip.com/i/b5d6xl
1
u/jbaker88 18d ago
"And here we have the HTTP DELETE verb. Can you guess where that goes? That's right! It goes in the POST endpoint!"
1
u/Ledeste 18d ago edited 18d ago
because that's the right way to handle it when you're not working at http level (or with dumb rest)
Reading the comments I feel so safe in my job x) as long as most people do not even understand why you should NOT use anything else than POST, there will be shitty legacy to remake :D
1
u/pxoqxo 18d ago
Someone told me post is most secured method. And now my all data gonna secure.
1
u/GoddammitDontShootMe 18d ago
When does anyone ever use anything that isn't GET or POST? This is the first I've even heard of PATCH.
1
u/fearthelettuce 17d ago
Why do people allow this?
1
u/darcygravan 16d ago
Http is over engineered.
-4
u/pjkm123987 19d ago
I legit make my personal project app api post only... Is there actually a drawback? seems to be working fine without issues and makes the api more straightfoward to use
0
u/swagwise_gamgee 18d ago
GraphQL 😎
-2
u/highcastlespring 19d ago
GET is not safe. POST encrypts your parameters.
PUT, the right way, but no one uses
-1
u/NebraskaGeek 18d ago
I've been using "post" for 20 years ever since I realized using "get" for everything wasn't the smartest secure solution
-2
u/cecil721 19d ago
Bro forgot QUERY exists now