Demo: safe pagination and sorting
On This Lesson 3 topics
This lesson is planned. The outline below lists the topics it will cover. The full lesson has not been published yet.
In this lesson
add capped paging and allow-listed sorting to the product list. Prepares JNR-019-LAB1.
Draft outline details
Step by step
- Add
page,size, andsortparameters with defaults toGET /products. - Cap
sizeat 100 and clamppageto 0 or more. - Add the sort allow-list with a tie-breaker on
id. - Planned mistake:
?sort=password(or any unknown field) is accepted and crashes. Fix: reject with400. - Return items plus page metadata and test with
size=1000and a bad sort field.
Practice
Apply this lesson with the module's lab, exercises and quiz.
Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.