2/21/2026 at 9:27:58 PM
It's something we debated in our team: if there's an API that returns data based on filters, what's the better behavior if no filters are provided - return everything or return nothing?The consensus was that returning everything is rarely what's desired, for two reasons: first, if the system grows, allowing API users to return everything at once can be a problem both for our server (lots of data in RAM when fetching from the DB => OOM, and additional stress on the DB) and for the user (the same problem on their side). Second, it's easy to forget to specify filters, especially in cases like "let's delete something based on some filters."
So the standard practice now is to return nothing if no filters are provided, and we pay attention to it during code reviews. If the user does really want all the data, you can add pagination to your API. With pagination, it's very unlikely for the user to accidentally fetch everything because they must explicitly work with pagination tokens, etc.
Another option, if you don't want pagination, is to have a separate method named accordingly, like ListAllObjects, without any filters.
by kgeist
2/21/2026 at 10:10:26 PM
Returning an empty result in that case may cause a more subtle failure. I would think returning an error would be a bit better as it would clearly communicate that the caller called the API endpoint incorrectly. If it’s HTTP a 400 Bad Request status code would seem appropriate.by alemanek
2/23/2026 at 7:50:57 PM
[dead]by pigpag
2/22/2026 at 7:07:17 PM
Neither of your options are good, the first question you need to ask is that is the filter optional or not ( this is a contract / API question ).If not optional then return 400, otherwise return all the results ( and have pagination ).
You should always have pagination in an API.
by Thaxll
2/21/2026 at 11:03:25 PM
>allowing API users to return everything at once can be a problem both for our server (lots of data in RAM when fetching from the DB => OOM, and additional stress on the DB)You can limit stress on RAM by streaming the data. You should ideally stream rows for any large dataset. Otherwise, like you say you are loading the entire thing into RAM.
by Philip-J-Fry
2/22/2026 at 8:30:00 PM
Not to mention the latency reduction!Buffering up the entire data set before encoding it to JSON and sending it is one of the biggest sources of latency in API based software. Streaming can get latencies down to tens of microseconds!
by jiggawatts
2/21/2026 at 9:36:19 PM
I like your thought process around the ‘empty’ case. While the opposite of a filter is no filter, to your point, that is probably not really the desire when it comes to data retrieval. We might have to revisit that ourselves.by MobileVet
2/22/2026 at 12:51:22 AM
But that query had parameter. They just fucked up parsing itby PunchyHamster
2/22/2026 at 12:57:16 AM
> to have a separate method named accordingly, like ListAllObjects, without any filtersFor me it's like `filter1=*`
by est
2/22/2026 at 9:30:47 AM
how about returning an error ? It’s the generic “client sent something wrong” bucket. Missing a required filter param is unambiguously a client mistake according to your own docs/contract → client error → 4xx family → 400 is the safest/default member of that family.by qwertyuiop_