Query parameters are a powerful way to customize API requests, allowing you to filter, sort, and paginate results. This guide introduces the concept of query parameters and how they’re used in the Literary Quotes API.
Query parameters are key-value pairs added to the end of a URL to modify the request. They start with a question mark (?) and are separated by ampersands (&).
A typical URL with query parameters looks like this:
http://localhost:3000/quotes?author=Jane+Austen&limit=5
In this example:
author=Jane+Austen filters quotes by the authorlimit=5 limits the response to 5 quotesThe Literary Quotes API supports several types of query parameters:
Get quotes by a specific author:
http://localhost:3000/quotes?author=Mark+Twain
Limit the number of results:
http://localhost:3000/quotes?limit=10
Combine multiple parameters:
http://localhost:3000/quotes?author=Jane+Austen&sort=publish_date&order=desc&limit=5
For a detailed guide on how to effectively use query parameters, including how to combine different types, see the Query parameters tutorial.
To learn more about different paramater types, see the following guides:
layout: page allowTitleToDifferFromFilename: Literary Quotes API type: guide —
The fields parameter allows you to specify which fields should be included in the API response. This can help reduce the amount of data transferred and processed, improving performance and efficiency.
By default, the Literary Quotes API returns all available fields for each quote. However, you may not always need all this information. The fields parameter lets you request only the specific fields you need.
To use the fields parameter, add it to your query string with a comma-separated list of the fields you want to include: http://localhost:3000/quotes?fields=author,quote,work Copy
The following fields are available:
Using curl:
curl "http://localhost:3000/quotes?fields=author,quote,work" \
-H "X-Bypass-Auth: true" \
-H "Accept: application/json"
Using Postman:
http://localhost:3000/quotes.id field is always included, even if not explicitly requested.