Quotable 是一个免费、开源的报价 API。它最初是作为 FreeCodeCamp 项目的一部分构建的。如果您有兴趣贡献,请查看贡献者指南。
每个 IP 地址每分钟 180 个请求的速率限制。如果超出速率限制,API 将响应429
错误。
https://api.quotable.io
您可以在我们的公共 Postman 工作区中试用该 API。
GET /random
从数据库返回一个随机引用
⛔️ 此方法已弃用,取而代之的是“获取随机报价”
查询参数
参数 | 类型 | 描述 |
---|---|---|
最大长度 | Int | 最大字符长度(可以与minLength 组合) |
最小长度 | Int | 以字符为单位的最小长度(可以与maxLength 组合) |
标签 | String | 获取带有特定标签的随机报价。这需要一个或多个标签名称的列表,用逗号(表示AND )或竖线(表示OR )分隔。逗号分隔的列表将匹配具有所有给定标签的引号。而竖线 ( | ) 分隔的列表将匹配具有任一提供的标签的引号。标签名称不区分大小写。多字标签可以是短横线(“标签名称”)或空格分隔(“标签名称”) |
作者 | String | 获取一位或多位作者的随机引用。该值可以是作者name 或slug 。要包含多个作者的引用,请提供用竖线分隔的作者姓名/别名列表。 |
作者ID | String | deprecated 与 author 参数相同,但它使用作者_id 而不是slug |
回复
{
_id: string
// The quotation text
content: string
// The full name of the author
author: string
// The `slug` of the quote author
authorSlug: string
// The length of quote (number of characters)
length: number
// An array of tag names for this quote
tags: string [ ]
}
GET /quotes/random
从数据库中获取一个或多个随机报价。此方法支持多个过滤器,可用于获取具有特定属性(即标签、报价长度等)的随机报价。
默认情况下,此方法返回一个随机引号。您可以通过limit
参数指定要返回的随机报价的数量。
️ 此方法相当于/random
端点。唯一的区别是响应格式:此方法返回一个Quote
对象Array
,而不是返回单个Quote
对象。
参数 | 类型 | 描述 |
---|---|---|
限制 | Int | default: 1 min: 1 max: 50 要检索的随机报价的数量。 |
最大长度 | Int | 最大字符长度(可以与minLength 组合) |
最小长度 | Int | 以字符为单位的最小长度(可以与maxLength 组合) |
标签 | String | 获取带有特定标签的随机报价。这需要一个或多个标签名称的列表,用逗号(表示AND )或竖线(表示OR )分隔。逗号分隔的列表将匹配具有所有给定标签的引号。而竖线 ( | ) 分隔的列表将匹配具有任一提供的标签的引号。标签名称不区分大小写。多字标签可以是短横线(“标签名称”)或空格分隔(“标签名称”) |
作者 | String | 获取一位或多位作者的随机引用。该值可以是作者name 或slug 。要包含多个作者的引用,请提供用竖线分隔的作者姓名/别名列表。 |
作者ID | String | deprecated 与 author 参数相同,但它使用作者_id 而不是slug |
回复
// An array containing one or more Quotes
Array < {
_id : string
// The quotation text
content : string
// The full name of the author
author : string
// The `slug` of the quote author
authorSlug : string
// The length of quote (number of characters)
length : number
// An array of tag names for this quote
tags : string [ ]
} >
示例
在浏览器中获取随机报价尝试
GET /quotes/random
获取 5 个随机引号在浏览器中尝试
GET /quotes/random?limit=3
带有标签“技术” AND
“著名引用”的随机引用在浏览器中尝试
GET /quotes/random?tags=technology,famous-quotes
带有“历史” OR
“民权”标签的随机引用在浏览器中尝试
GET /quotes/random?tags=history|civil-rights
最大长度为 50 个字符的随机引用在浏览器中尝试
GET /quotes/random?maxLength=50
长度在 100 到 140 个字符之间的随机引用在浏览器中尝试
GET /quotes/random?minLength=100&maxLength=140
GET /quotes
获取与给定查询匹配的所有引号。默认情况下,这将返回所有报价的分页列表,按_id
排序。引文还可以按作者、标签和长度进行过滤。
查询参数
参数 | 类型 | 描述 |
---|---|---|
最大长度 | Int | 最大字符长度(可以与minLength 组合) |
最小长度 | Int | 以字符为单位的最小长度(可以与maxLength 组合) |
标签 | String | 按标签过滤报价。获取一个或多个标记名称的列表,用逗号(表示AND )或竖线(表示OR )分隔。逗号分隔的列表将匹配具有所有给定标签的引号。而竖线 ( | ) 分隔的列表将匹配具有任一提供的标签的引号。标签名称不区分大小写。多字标签可以是短横线(“标签名称”)或空格分隔(“标签名称”) |
作者 | String | 获取特定作者的引用。该值可以是作者name 或slug 。要获取多个作者的引用,请提供用竖线分隔的作者姓名/slugs 列表。 |
作者ID | String | deprecated 与 author 参数相同,但它使用作者_id 而不是slug |
排序方式 | enum | Default: "dateAdded" values: "dateAdded", "dateModified", "author", "content" 用于对报价进行排序的字段 |
命令 | enum | values: "asc", "desc" default: depends on sortBy 结果的排序顺序。默认顺序取决于 sortBy 字段。对于按字母顺序排序的字符串字段,默认顺序为升序。对于数字和日期字段,默认顺序是降序。 |
限制 | Int | Min: 1 Max: 150 Default: 20 设置每页的结果数。 |
页 | Int | Min: 1 Default: 1 要返回的结果页面。如果该值大于总页数,请求将不会返回任何结果 |
回复
{
// The number of quotes returned in this response
count: number
// The total number of quotes matching this query
totalCount: number
// The current page number
page: number
// The total number of pages matching this request
totalPages: number
// The 1-based index of the last result included in the current response.
lastItemIndex: number
// The array of quotes
results : Array < {
_id : string
// The quotation text
content : string
// The full name of the author
author : string
// The `slug` of the quote author
authorSlug : string
// The length of quote (number of characters)
length : number
// An array of tag names for this quote
tags : string [ ]
} >
}
示例
获取第一页报价,每页 20 个结果在浏览器中尝试
GET /quotes?page=1
获取第二页报价,每页 20 个结果在浏览器中尝试
GET /quotes?page=2
获取带有love
OR
happiness
标签的所有引言,请尝试在浏览器中尝试
GET /quotes?tags=love|happiness
在浏览器中尝试使用标签technology
AND
famous-quotes
获取所有引用
GET /quotes?tags=technology,famous-quotes
使用作者的slug
获取作者的所有引用。在浏览器中尝试
GET /quotes?author=albert-einstein
GET /quotes/:id
通过 ID 获取报价
回复
{
_id: string
// The quotation text
content: string
// The full name of the author
author: string
// The length of quote (number of characters)
length: number
// An array of tag names for this quote
tags: string [ ]
}
GET /authors
获取与给定查询匹配的所有作者。此端点可用于列出作者,并提供多个排序和过滤选项。它还可用于使用作者 slug 或 ids 获取一位或多位特定作者的作者详细信息。
查询参数
参数 | 类型 | 描述 |
---|---|---|
蛞蝓 | string | 按 slug 过滤作者。该值可以是一个或多个作者 slugs。要通过 slug 获取多个作者,该值应该是以竖线分隔的 slug 列表。 |
排序方式 | enum | Default: "name" values: "dateAdded", "dateModified", "name", "quoteCount" 用于对作者进行排序的字段。 |
命令 | enum | values: "asc", "desc" 结果的排序顺序。默认顺序取决于 sortBy 字段。对于按字母顺序排序的字符串字段(即 name ),默认顺序为升序。对于数字和日期字段(即quoteCount ),默认顺序是降序。 |
限制 | Int | Min: 1 Max: 150 Default: 20 设置每页的结果数。 |
页 | Int | Min: 1 Default: 1 要返回的结果页面。如果该值大于总页数,请求将不会返回任何结果 |
回复
{
// The number of results included in this response.
count: number
// The total number of results matching this request.
totalCount: number
// The current page number
page: number
// The total number of pages matching this request
totalPages: number
// The 1-based index of the last result included in this response. This shows the
// current pagination offset.
lastItemIndex: number | null
// The array of authors
results : Array < {
// A unique id for this author
_id : string
// A brief, one paragraph bio of the author. Source: wiki API
bio : string
// A one-line description of the author. Typically it is the person's primary
// occupation or what they are know for.
description : string
// The link to the author's wikipedia page or official website
link : string
// The authors full name
name : string
// A slug is a URL-friendly ID derived from the authors name. It can be used as
slug : string
// The number of quotes by this author
quoteCount : string
} >
}
示例
获取所有作者,按姓名字母顺序排序尝试在浏览器中尝试
GET /authors?sortBy=name
获取所有作者,按引用数量降序排序尝试在浏览器中尝试
GET /authors?sortBy=quoteCount&order=desc
通过 slug 获取单个作者。在浏览器中尝试
GET /authors?slug=albert-einstein
通过 slug 获取多个作者。在这种情况下,您可以在浏览器中提供一个以竖线分隔的 slugs 列表。
GET /authors?slug=albert-einstein|abraham-lincoln
GET /search/quotes
此端点允许您按关键字、内容和/或作者姓名搜索引用。与列表报价端点不同,此方法由 Atlas Search 提供支持,旨在为搜索栏 UI 提供支持。
查询参数
参数 | 类型 | 描述 |
---|---|---|
询问 | String | 搜索字符串。可以将查询括在引号中以搜索确切的短语。 |
领域 | String | Default: "content,author,tags" 指定要搜索的字段。这需要一个逗号分隔的字段名称列表。支持的搜索字段为“内容”、“作者”、“标签”。默认情况下,它将同时搜索所有字段。 |
模糊最大编辑 | Int | Min: 0 Max: 2 Default: 0 匹配指定搜索词所需的单字符编辑的最大数量。将其设置为零会禁用模糊匹配。 |
模糊最大扩展 | Int | Max: 150 Min: 0 Default: 50 启用模糊搜索时,这是要生成和搜索的变体的最大数量。此限制适用于每个代币。 |
限制 | Int | Min: 0 Max: 150 Default: 20 每页最大结果数 |
页 | Int | Min: 1 Default: 1 设置分页的页码 |
回复
{
// The number of results included in this response.
count: number
// The total number of results matching this request.
totalCount: number
// The current page number
page: number
// The total number of pages matching this request
totalPages: number
// The 1-based index of the last result included in this response. This shows the
// current pagination offset.
lastItemIndex: number | null
// The array of authors
results : Array < {
// A unique id for this author
_id : string
// A brief, one paragraph bio of the author. Source: wiki API
bio : string
// A one-line description of the author. Typically it is the person's primary
// occupation or what they are know for.
description : string
// The link to the author's wikipedia page or official website
link : string
// The authors full name
name : string
// A slug is a URL-friendly ID derived from the authors name. It can be used as
slug : string
// The number of quotes by this author
quoteCount : string
} >
}
示例
搜索“每一个好的技术基本上都是魔法”(在浏览器中尝试)
GET /search/quotes?query=every good technology is basically magic
结果:
- “任何足够先进的技术都等同于魔法。”
搜索词组“分房”
GET /search/quotes?query=divided house
结果
- “一个内部分裂的房子是站不住脚的。”
搜索带有关键字“life”或“happiness”的引言(在浏览器中尝试)
GET /search/quotes?query=life happiness
搜索名为“kennedy”的作者的引言(在浏览器中尝试)
GET /search/quotes?query=Kennedy&fields=author
GET /search/authors
此端点允许您按姓名搜索作者。它旨在为作者提供搜索栏,在用户键入时显示自动完成建议。
Example
query="John F. Kennedy"
terms=["john", "kennedy"]
term term
| |
John F. Kennedy Jr.
| |
initial suffix
Example
query="Saint Augustine of Hippo"
terms=["Augustine", "Hippo"]
term term
| |
Saint Augustine of Hippo
| |
prefix stopword
查询参数
参数 | 类型 | 描述 |
---|---|---|
询问 | String | 搜索查询 |
自动完成 | Boolean | default: true 启用自动完成匹配 |
匹配阈值 | Int | Min: 1 Max: 3 Default: 2 设置作者必须匹配才能包含在结果中的搜索词(单词)的最小数量。基本上,如果将其设置为 1,结果将包括与姓名的至少一部分匹配的所有作者。因此,query="John F. Kennedy" 的结果将包括与“john” OR “kennedy”匹配的所有作者。如果将此设置为 2 :当搜索查询包含两个或多个“术语”时,这些术语中至少有两个必须匹配。因此,query="John F. Kennedy" 只会返回与“John” AND “Kennedy”匹配的作者。 |
限制 | Int | Min: Max: 150 Default: 20 每页最大结果数 |
页 | Int | Min: 1 Default: 1 设置分页的页码 |
回复
{
// The number of results included in this response.
count: number
// The total number of results matching this request.
totalCount: number
// The current page number
page: number
// The total number of pages matching this request
totalPages: number
// The 1-based index of the last result included in this response. This shows the
// current pagination offset.
lastItemIndex: number | null
// The array of authors
results : Array < {
// A unique id for this author
_id : string
// A brief, one paragraph bio of the author. Source: wiki API
bio : string
// A one-line description of the author. Typically it is the person's primary
// occupation or what they are know for.
description : string
// The link to the author's wikipedia page or official website
link : string
// The authors full name
name : string
// A slug is a URL-friendly ID derived from the authors name. It can be used as
slug : string
// The number of quotes by this author
quoteCount : string
} >
}
示例
搜索名为“Einstein”的作者(在浏览器中尝试)
GET /search/authors?query=Einstein
结果:
- 阿尔伯特·爱因斯坦
自动完成搜索“Einstein”(在浏览器中尝试)
GET /search/authors?query=Einst
结果:
- 阿尔伯特·爱因斯坦
搜索“John Adams”(在浏览器中尝试)
GET /search/authors?query=john adams
结果
- 约翰·亚当斯
- 约翰·昆西·亚当斯
搜索“John Quincy Adams”(在浏览器中尝试)
GET /search/authors?query=john quincy adams
结果:
- 约翰·昆西·亚当斯)
- 约翰·亚当斯
通过slug
获取单个Author
。此方法可用于获取作者详细信息,例如简介、网站链接和个人资料图片。
如果您想获取特定作者的所有引用,请使用 /quotes 端点并按作者作者姓名/slug 进行过滤。
如果您想在单个请求中通过 slug 获取多个作者,请使用 /authors 端点并按slug
进行过滤。
GET /authors/:id
回复
{
// A unique id for this author
_id: string
// A brief, one paragraph bio of the author. Source wiki API.
bio: string
// A one-line description of the author.
description: string
// The link to the author's wikipedia page or official website
link: string
// The authors full name
name: string
// A slug is a URL-friendly ID derived from the authors name. It can be used as
slug: string
// The number of quotes by this author
quoteCount: string
}
GET /tags
获取所有标签的列表
查询参数
参数 | 类型 | 描述 |
---|---|---|
排序方式 | enum | Default: "name" values: "dateAdded", "dateModified", "name", "quoteCount" 用于对标签进行排序的字段。 |
命令 | enum | values: "asc", "desc" 结果的排序顺序。默认顺序取决于 sortBy 字段。对于按字母顺序排序的字符串字段,默认顺序为升序。对于数字和日期字段,默认顺序是降序。 |
回复
{
// The number of all tags by this request
count: number
// The array of tags
results : Array < {
_id : string
name : string
} >
}