服務索引
服務索引是 JSON 檔,這是 NuGet 套件來源的進入點,可讓用戶端實作探索套件來源的功能。 服務索引是具有兩個必要屬性的 JSON 物件: version
(服務索引的架構版本) ,並 resources
(套件來源) 的端點或功能。
nuget.org 的服務索引位於 https://api.nuget.org/v3/index.json
。
版本控制
此值 version
是 SemVer 2.0.0 可剖析的版本字串,表示服務索引的架構版本。 API 會要求版本字串具有 的主要版本號碼 3
。 由於對服務索引架構進行非中斷性變更,版本字串的次要版本將會增加。
服務索引中的每個資源都會獨立于服務索引架構版本進行版本設定。
目前的架構版本為 3.0.0
。 版本 3.0.0
的功能相當於舊 3.0.0-beta.1
版,但應該更清楚傳達穩定且定義的架構。
HTTP 方法
服務索引可以使用 HTTP 方法和 GET
HEAD
來存取。
資源
屬性 resources
包含此套件來源所支援的資源陣列。
資源
資源是陣列中的 resources
物件。 它代表封裝來源的版本化功能。 資源具有下列屬性:
名稱 | 類型 | 必要 | 注意 |
---|---|---|---|
@id | 字串 | 是 | 資源的 URL |
@type | 字串 | 是 | 表示資源類型的字串常數 |
comment | 字串 | 否 | 資源的人類可讀描述 |
@id
是必須絕對且必須具有 HTTP 或 HTTPS 架構的 URL。
@type
用來識別與資源互動時要使用的特定通訊協定。 資源的類型是不透明的字串,但通常具有格式:
{RESOURCE_NAME}/{RESOURCE_VERSION}
用戶端預期會將他們瞭解的值硬式編碼 @type
,並在套件來源的服務索引中查閱這些值。 目前使用的確切 @type
值會列舉在 API 概觀所列的個別資源參考檔上。
為了本檔的目的,不同資源的相關檔基本上會依 {RESOURCE_NAME}
服務索引中找到的 分組,類似于依案例分組。
不需要每個資源都有唯 @id
一的 或 @type
。 由用戶端實作決定要偏好的資源,而非另一個資源。 其中一個可能的實作是,在連線失敗或伺服器錯誤時,相同或相容的 @type
資源可以迴圈配置資源的方式使用。
範例要求
GET https://api.nuget.org/v3/index.json
範例回應
{
"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."
}
]
}