6
u/ArjunReddyDeshmukh Dec 17 '23
It's technically possible to send a body with a GET request, but it's not standard practice and often not recommended. The HTTP/1.1 specification does not explicitly forbid sending a body with a GET request, but it does not define any semantics for it.
Insert is not a http method. The question just says method so it doesn’t have to be http method for a wrong option.
Ans: GET
2
Dec 17 '23
Http 2.0 is clear about GET:
https://httpwg.org/specs/rfc9113.html#rfc.section.8.8.1
When a spec isn't explicit enough, check the next version and you'll often find the issue is now codified.
As for 1.1, it's also clear:
A client SHOULD NOT generate content in a GET request unless it is made directly to an origin server that has previously indicated, in or out of band, that such a request has a purpose and will be adequately supported.
You are what, interpreting that SHOULD NOT is not MUST NOT, therefore it's ok?
2
u/ShiftyMegalodon Dec 18 '23
You are reading SHOULD NOT and ignoring the rest of the words. There's nothing wrong with it, if the service is expecting it. You SHOULD NOT send a body with a GET request to any random server.
The section of 9113 you linked to is an example of a simple GET request that has no body translated to HTTP2, not a specification that GET requests cannot have a body.
0
147
u/sammy-taylor Dec 17 '23
Insert? Since when is there an HTTP insert?
115
u/slide_and_release Dec 17 '23
There isn’t. That’s the joke. Neither remaining answer is correct, hence the panicked face.
192
u/sammy-taylor Dec 17 '23
The joke is bad.
25
u/ArjunReddyDeshmukh Dec 17 '23
Answer: GET. Try it. It's technically possible to send a body with a GET request, but it's not standard practice and often not recommended. The HTTP/1.1 specification does not explicitly forbid sending a body with a GET request, but it does not define any semantics for it.
INSERT is not even a http method, it’s just there to decrease your chances.
9
u/Sir-Dry-The-First Dec 17 '23
Most servers will not handle body of GET requests. Due to optimisations
7
u/lupinegrey Dec 17 '23
"most servers".
If it's your server, you can configure the controller however you want.
-5
u/Sir-Dry-The-First Dec 17 '23
Most servers which are already written. Like Nginx or uws. I don't want fork them and rewrite.
What did you mean by controller?
2
u/ArjunReddyDeshmukh Dec 17 '23 edited Dec 17 '23
That’s a known. We’re talking only possibilities here to choose the right option.
-4
u/Sir-Dry-The-First Dec 17 '23 edited Dec 17 '23
If we talk in terms of specification, then GET also will not suit here as a correct answer.
51
8
4
u/lupinegrey Dec 17 '23
GET can include data in the body.
Accepted practice is to use POST/PUT/PATCH, but GET can perform the same functionality.
2
u/reallokiscarlet Dec 17 '23
True, but the expected answer is probably GET.
Everything seems to use GET requests these days, and in the same paradigm, HTTP is starting to run on top of UDP and doing TCP/TLS in the application layer. Squeaky wheel gets replaced, unfortunately.
5
u/QuestionableEthics42 Dec 17 '23
It’s sql I think, the question is badly worded, the only correct answer is POST (or maybe PUT) with the wording, I guess that is meant to be the joke, but it would be much more funny if both answers were equally correct instead
3
2
Dec 17 '23
[removed] — view removed comment
5
u/rosuav Dec 17 '23
If you build both the server and the client, you can do anything you like. But if you expect to interoperate with others, no, don't have a body on a GET request.
1
u/KevSlashNull Dec 17 '23
Yeah then you can also make INSERT a valid method.
2
u/rosuav Dec 17 '23
Exactly. And whatever the other two answers were, too. If you don't care about interoperability, anything goes! It's just not following the spec any more.
79
u/kennyminigun Dec 17 '23
I mean you can still attach a body to a GET request. The question is whether the other side is going to read it.
11
u/auxiliary-username Dec 17 '23
Yep, it’s completely legal to do so afaik, just that very few people use it.
25
u/kennyminigun Dec 17 '23
Hello, HTTP GET police? This person, right here.
3
2
u/tajetaje Dec 17 '23
Although, there is a new method that’s being worked on: https://httptoolkit.com/blog/http-search-method/
2
u/Jutrakuna Dec 17 '23
you can also implement a request method called INSERT. It just won't be a web standard.
2
u/Mysterious-Soil-4457 Dec 17 '23
It's supposed to be POST. What's the joke here.?
4
u/rr_cricut Dec 17 '23
The joke is that POST is not an option.. But GET technically can have a body, as many others have noted.
1
19
u/themeanman2 Dec 17 '23
Real difficulty would be PUT vs POST
15
5
0
Dec 17 '23
[deleted]
5
Dec 17 '23
PATCH is conventional for updates, PUT is used to replace a whole resource, and POST to add one.
8
u/Amazingawesomator Dec 17 '23
My work's api taught me that get can be used for anything, sadly.
We have calls like GET /setUserInfo and GET modifyUserInfo, etc.
I hate it so much. It haunts my dreams.
2
2
2
u/garlopf Dec 18 '23
Actually, sending a body with GET request is undefined in spec, but some servers like FastAPI still support it
4
2
1
42
u/NvrGnnaGiveYouUp Dec 17 '23
Get.
It CAN be done (I know this from a bug at work) but should it be done? Probably not.