Given a REST API that uses offset-based pagination, the client requests page 3 with a page size of 10. What is the offset value sent to the server?
page = 3 page_size = 10 offset = (page - 1) * page_size print(offset)
Offset is how many items to skip before starting to collect the page.
Offset is calculated as (page - 1) * page_size. For page 3 and page size 10, offset = (3 - 1) * 10 = 20.
Choose the statement that correctly describes offset-based pagination in REST APIs.
Think about how offset is calculated using page number and size.
Offset-based pagination calculates the number of items to skip using page number and page size, then fetches the next set of items.
Look at the code below. It is supposed to return the first page of results but returns an empty list. What is the cause?
def get_page(data, page, page_size): offset = page * page_size return data[offset:offset + page_size] items = list(range(5)) print(get_page(items, 1, 10))
Remember that page 1 means no items skipped.
Offset should be (page - 1) * page_size. The current code skips the first page entirely by starting at offset = page * page_size.
Choose the code snippet that correctly calculates offset and slices the data list for pagination.
data = list(range(100)) page = 4 page_size = 15
Offset must skip items from previous pages.
Offset is (page - 1) * page_size to skip items from earlier pages. Then slice from offset to offset + page_size.
Assume a dataset of 95 items. A client requests page 10 with a page size of 10 using offset-based pagination. How many items will the server return?
Calculate offset and see how many items remain after skipping.
Offset = (10 - 1) * 10 = 90. There are 95 items total, so 95 - 90 = 5 items remain to return.