Quick revision
The short answer
I would design GET /orders?status=SHIPPED&from=2026-01-01&to=2026-03-31&page=0&size=50&sort=createdAt,desc. The filters bind to a validated record such as OrderFilter(status, from, to) used as a method parameter without @RequestBody, the dates use ISO format with @DateTimeFormat(iso = ISO.DATE), and page, size and sort bind to Spring Data's Pageable with a maximum page size. Allowed sort fields are checked against an allow-list, and the response carries paging metadata in one consistent format.
What to remember
In this answer, we designed GET /orders with status, from and to filters, ISO dates and page, size and sort parameters. We bound the filters to a validated record without @RequestBody, used @DateTimeFormat(iso = ISO.DATE) for the dates, let Spring Data's Pageable handle paging with a maximum page size, checked sort fields against an allow-list, built the query with a Specification, and returned paging metadata in a consistent shape.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
I would design GET /orders?status=SHIPPED&from=2026-01-01&to=2026-03-31&page=0&size=50&sort=createdAt,desc. The filters bind to a validated record such as OrderFilter(status, from, to) used as a method parameter without @RequestBody, the dates use ISO format with @DateTimeFormat(iso = ISO.DATE), and page, size and sort bind to Spring Data's Pageable with a maximum page size. Allowed sort fields are checked against an allow-list, and the response carries paging metadata in one consistent format.
Why this question is asked
Almost every API has a list endpoint, and list endpoints are where APIs most often grow messy: ten @RequestParam arguments, three date formats, unbounded page sizes, and sorting by any column a client can guess. Interviewers ask this to see whether we can design a clean contract and bind it with little code. In this answer, we will design the parameters, bind the filters to a record, add paging and sorting with Pageable, validate everything, and return the results in a consistent shape.
1Designing the Parameters
We start with the contract, because the code follows from it. Filters are named after fields the client understands: status, from and to. Dates use ISO 8601, 2026-01-01, which every language can produce and which sorts correctly as text. The date range is inclusive of from and exclusive of to, or inclusive of both; the important thing is to choose one and document it. Paging uses page and size, starting at page 0 as Spring Data does, and sorting uses sort=field,direction and can repeat for several fields.
2Binding the Filters to a Record
Rather than five @RequestParam arguments, we bind the filters to one record. A method parameter of a non-simple type without an annotation is treated as a model attribute, so Spring binds query parameters to it by name, through the record's constructor.
Notice that the enum list converts automatically: the conversion service turns each repeated status value into an OrderStatus, and an unknown value is a binding error. Notice also that @Valid works on the bound record, so the cross-field rule that from is not after to is checked before our code runs. Binding failures and validation failures on a model attribute are reported together as a 400, MethodArgumentNotValidException in current Spring versions (check your version; older ones used BindException).
3Paging and Sorting With Pageable
Spring Data's web support adds an argument resolver for Pageable, which reads page, size and sort from the query string. Spring Boot configures it, and lets us set limits through properties. The most important limit is the maximum page size, so nobody can request a million rows in one call.
- Bind status, from, to to OrderFilterConversion service, ISO dates, enums
- Validate the filter
@Validwith the range rule - Resolve PageableDefaults, max page size 100
- Sort fields allowed?
createdAt, total, statusYesBuild the queryNo400 Cannot sort by field - Run query with LIMIT and OFFSETPlus a count query
- Return content and page metadataSame shape on every list endpoint
6 steps in order. Play them, or step through them one at a time.
Why the sort allow-list? Without it, Spring Data passes the property path to the query, so a client can sort by nested paths or by columns that have no index, which can turn one request into a full table scan. Sorting by a sensitive field can even leak information through the order of results. The allow-list keeps sorting to fields we have indexed and intend to expose.
4Building the Query
The service turns the filter into a query. With Spring Data JPA, a Specification composes optional conditions cleanly, adding only the conditions whose values are present.
Notice the date handling. The column is a timestamp, but the filter is a date, so to is turned into less than the start of the next day. That makes the range inclusive of the whole last day, which is what people usually mean, and the documentation should say so. Specification.allOf skips null parts; check your Spring Data version for its exact composition helpers.
5Returning Paging Metadata Consistently
Serialising a Spring Data Page directly produces a large, unstable JSON structure, and Spring Data now warns about it. Wrapping it in PagedModel, or setting @EnableSpringDataWebSupport(pageSerializationMode = VIA_DTO), gives a stable shape. For many services, a company-wide paging record does the same job and keeps every list endpoint identical.
For very large tables, the count query behind totalElements can be expensive, and deep offsets get slow. There, cursor-based paging, where the client sends the last seen sort key instead of a page number, scales better. It is a good point to raise if the interviewer asks about millions of rows.
6Follow-up questions
Why not accept the filter as a JSON body?
GET requests with bodies are poorly supported by proxies, caches and many clients, and HTTP gives them no defined meaning. Query parameters are visible in logs and links and are cacheable. For truly complex searches, a POST /orders/search with a body is an accepted alternative, but simple filters belong in the query string.
How do you document the defaults and limits?
In the OpenAPI spec. springdoc-openapi understands Pageable when configured and can show page, size and sort, and the spec should state the default sort, the maximum page size and the allowed sort fields, so clients do not discover them by trial.
7Conclusion
In this answer, we designed GET /orders with status, from and to filters, ISO dates and page, size and sort parameters. We bound the filters to a validated record without @RequestBody, used @DateTimeFormat(iso = ISO.DATE) for the dates, let Spring Data's Pageable handle paging with a maximum page size, checked sort fields against an allow-list, built the query with a Specification, and returned paging metadata in a consistent shape.
Open with
I'd design it as GET /orders with status, from and to as filters, page, size and sort for paging, for example status=SHIPPED&from=2026-01-01&to=2026-03-31&page=0&size=50&sort=createdAt,desc. Status can repeat to filter by several values.
Then, if they want more
Dates are ISO 8601, and I'd document that the range includes the whole last day. In the controller, rather than a long list of @RequestParam arguments, I bind the filters to a record, OrderFilter, as a parameter without @RequestBody, so Spring binds query parameters to it by name.
The dates get @DateTimeFormat with ISO.DATE, the status list converts to an enum, and @Valid checks it, including a cross-field rule that from isn't after to, so bad input is a 400. For paging I use Spring Data's Pageable with @PageableDefault and set spring.data.web.pageable.max-page-size, say 100, so nobody requests a million rows.
I'd also check sort fields against an allow-list, because otherwise clients can sort by any property path, including unindexed or sensitive fields. The service builds a Specification from the filter, adding only the conditions that are set.
The response uses one consistent format, content plus page metadata, via PagedModel or a shared paging record, and for very large tables I'd mention cursor paging.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Spring Framework reference, Spring Web MVC
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Design the query parameters for GET /orders with filtering by status, date range...": https://scrivio-interview-library.netlify.app/spring-boot/rest-controllers/21a5d7545c/