Service index

服务索引是 NuGet 包源的入口点的 JSON 文档,允许客户端实现发现包源的功能。 服务索引是一个 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 必须是绝对 URL,并且必须具有 HTTP 或 HTTPS 架构。

用于 @type 标识与资源交互时要使用的特定协议。 资源的类型是不透明的字符串,但通常采用以下格式:

{RESOURCE_NAME}/{RESOURCE_VERSION}

客户端应对它们理解的值进行硬编码 @type ,并在包源的服务索引中查找它们。 在 API 概述中列出的单个资源引用文档中枚举当前使用的确切@type值。

为了获得本文档,有关不同资源的文档实质上将由服务索引中找到的文档分组 {RESOURCE_NAME} ,类似于按方案分组。

不需要每个资源具有唯 @id 一的或 @type。 由客户端实现决定哪个资源优先于另一个资源。 一种可能的实现是,在连接失败或服务器错误的情况下,可以采用轮循机制方式使用相同或兼容的 @type 资源。

资源可以使用不同于服务索引的主机或域,但这可能会导致具有严格网络规则的环境中出现问题。 具体而言,如果服务索引将直接指向 nuget.org 的资源(而不是通过自己的源进行代理或缓存),则源将无法在阻止访问 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."
    }
  ]
}