GET or POST in API
Hey, quick programming question because we’ve got a heated discussion in company.I’ve got a REST endpoint that fetches data about the number of kids in specific facilities within a given date range (e.g., from August 1st to August 31st). Right now, I’m using POST, and in the request body I pass an object that contains a list of facility IDs and the date range (from / to). The discussion started because some people say it should be a GET instead of a POST, but in my opinion POST makes more sense here. Otherwise, I’d have to either pass dozens of companyId values in the URL or call the endpoint multiple times, which feels wrong.
So what do you think — are you team POST or GET here? Or maybe there’s a secret third option I don’t know about?

18 Replies
⌛
This post has been reserved for your question.
Hey @Slownik1! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./close
or theClose Post
button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
POST is for creating stuff
Otherwise, I’d have to either pass dozens of companyId values in the URL or call the endpoint multiple times, which feels wrong.
No you can just use a body to pass all the input you want not recommended but possible, but as query params would be more the norm
So yes GET would be correct
you can pass lists as a parameter in get requests
and its frontends job to prepare the parameters properlty
POST is obviously cleaner, but then modern programmers disagree with me on everything. Team POST should consider rejecting modern programming and modern culture.
This is wrong in two ways:
- Post is not just for creating stuff, it can also be used for everything that doesn't fit any other method
- By the spec GET should not have a body
So you want to GET some Information about kids in specific facilities than you should use a GET
By the spec GET should not have a body
did you even read my response?
not recommended but possible
next sentence
query params would be more the norm
Post is not just for creating stuff
it commonly used to do it
and in your usecase its def a GET
you would use a post if your query would get to long (over 8kb)It's not like you need to write the query by hand.
Also true
you can input it here

how is it cleaner
Long URLs are ugly. And JSON can be logged for debugging.
url will get ugly for who
backend doesnt even view the url
and frontend builds the url with parameters
not manually
and u can debug the parameters aswell
ez
URLs show up in error logs, for example. Ugliness should be avoided as a matter of principle.
so what if they show up in error logs
its not like the url gonna have 500 parameters
in this example
and get is specifically made for querying data
so im absolutely right
Dozens is bad enough.
Decent people should violate the rules of modern programmers and modern culture whenever possible.
you forgot to add 'and then complain about being fired for unmaintainable code'
ahahahah
I am starting to get (🥁) why.
💤
Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping
.
Warning: abusing this will result in moderative actions taken against you.