服務索引是 JSON 檔,它是 NuGet 套件來源的進入點,可讓客戶端實作探索套件來源的功能。 服務索引是 JSON 物件,其中包含兩個必要屬性: version (服務索引的架構版本)和 resources (封裝來源的端點或功能)。
nuget.org 的服務索引位於 https://api.nuget.org/v3/index.json。
Versioning
值為 version SemVer 2.0.0 可剖析的版本字串,表示服務索引的架構版本。 API 會強制版本字串具有 3的主要版本號碼。 由於對服務索引架構進行非中斷性變更,版本字串的次要版本將會增加。
服務索引中的每個資源都會獨立於服務索引架構版本進行版本設定。
目前的架構版本是 3.0.0。 版本 3.0.0 在功能上相當於舊 3.0.0-beta.1 版,但應優先使用,因為它更清楚地傳達穩定且定義的架構。
HTTP methods
服務索引可使用 HTTP 方法和 GETHEAD來存取。
Resources
屬性 resources 包含這個套件來源所支援的資源數位列。
Resource
資源是陣列中的 resources 物件。 它代表封裝來源的版本化功能。 資源具有下列屬性:
| Name | 類型 | Required | Notes |
|---|---|---|---|
| @id | 字串 | yes | 資源的 URL |
| @type | 字串 | yes | 表示資源類型的字串常數 |
| 留言 | 字串 | no | 資源的人類可讀描述 |
@id是必須是絕對的 URL,而且必須具有 HTTP 或 HTTPS 架構。
@type用來識別與資源互動時要使用的特定通訊協定。 資源的類型是不透明的字串,但通常具有格式:
{RESOURCE_NAME}/{RESOURCE_VERSION}
用戶端預期會將他們瞭解的值硬式編碼 @type ,並在套件來源的服務索引中查閱這些值。 目前使用的確切 @type 值會列舉於 API 概觀中列出的個別資源參考檔上。
為了此文件,有關不同資源的檔基本上會依 {RESOURCE_NAME} 服務索引中找到的 群組,類似於依案例分組。
不需要每個資源都有唯 @id 一或 @type。 由客戶端實作決定哪一個資源優先於另一個資源。 其中一個可能的實作是,在聯機失敗或伺服器錯誤的情況下,可以使用相同或相容的 @type 資源,以迴圈配置資源的方式使用。
資源可以使用與服務索引不同的主機或網域,但這可能會在具有嚴格網路規則的環境中造成問題。 特別是,如果您的服務索引新增直接指向 nuget.org 的資源(而不是透過您自己的摘要進行 Proxy 或快取),您的摘要將無法在封鎖存取 nuget.org 的地方運作。 如果您的摘要將特定資源委派給 nuget.org,建議您新增設定,以便在部署摘要時,從服務索引中移除直接 nuget.org 參考。
Sample request
GET https://api.nuget.org/v3/index.json
Sample response
{
"version": "3.0.0",
"resources": [
{
"@id": "https://api.nuget.org/v3-flatcontainer/",
"@type": "PackageBaseAddress/3.0.0",
"comment": "Base URL of Azure storage where NuGet package registration info for NET Core is stored, in the format https://api.nuget.org/v3-flatcontainer/{id-lower}/{id-lower}.{version-lower}.nupkg"
},
{
"@id": "https://www.nuget.org/api/v2/package",
"@type": "PackagePublish/2.0.0"
},
{
"@id": "https://api-v2v3search-0.nuget.org/query",
"@type": "SearchQueryService/3.0.0-rc",
"comment": "Query endpoint of NuGet Search service (primary) used by RC clients"
},
{
"@id": "https://api-v2v3search-0.nuget.org/autocomplete",
"@type": "SearchAutocompleteService/3.0.0-rc",
"comment": "Autocomplete endpoint of NuGet Search service (primary) used by RC clients"
},
{
"@id": "https://api.nuget.org/v3/registration2/",
"@type": "RegistrationsBaseUrl/3.0.0-rc",
"comment": "Base URL of Azure storage where NuGet package registration info is stored used by RC clients. This base URL does not include SemVer 2.0.0 packages."
}
]
}