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
} >
}