分享方式:


服務索引

服務索引是 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 方法和 GETHEAD來存取。

資源

屬性 resources 包含這個套件來源所支援的資源數位列。

資源

資源是陣列中的 resources 物件。 它代表封裝來源的版本化功能。 資源具有下列屬性:

名稱 類型​​ 必要 備註
@id string 資源的 URL
@type string 表示資源類型的字串常數
comment string 資源的人類可讀描述

@id是必須是絕對的 URL,而且必須具有 HTTP 或 HTTPS 架構。

@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."
    }
  ]
}