/search, and a query string with parameters.
Everything to the right of the question mark constitutes the query parameters. These optional parameters help refine results, such as retrieving posts created in the last two hours or posts with over 100 likes. In Yelp’s case, a parameter like find_location=Miami, Florida instructs the API to filter results by location.

Setting Up the Endpoint
Consider a basic endpoint for retrieving posts. Initially, it might look like this:Adding a Limit Query Parameter
To allow clients to specify the number of posts returned (for example, 10 or 50), add alimit query parameter with a default value of 10:
/posts?limit=3 to ensure that only three posts are returned.
Implementing Pagination with Skip and Limit
To support pagination, include askip query parameter that allows clients to bypass a specified number of posts. The skip parameter is an integer with a default value of 0. SQLAlchemy’s offset function helps achieve this:
/posts?limit=2&skip=1 will return posts starting from the second result. Sample log outputs might look like:
Enhancing Search Functionality
In addition to pagination, you can let users search for posts by keywords in the title. Add an optionalsearch query parameter, defaulting to an empty string, and use SQLAlchemy’s filtering to search within the title field:
/posts?limit=2&skip=1&search=beaches will filter posts to those whose titles contain “beaches”. Console outputs may look like:
Handling Spaces in Search Queries
When the search term contains spaces (for example, “beaches hello”), ensure you URL-encode the space as%20. For example:
Final Combined Implementation
Below is the complete implementation of the endpoint that supports limiting, skipping, and searching:You can test the API endpoints using various query parameters:
•
/posts?limit=3 retrieves three posts.
• /posts?limit=2&skip=1 retrieves posts after skipping the first one.
• /posts?limit=2&skip=1&search=beaches filters posts based on the keyword “beaches” in the title.