服务索引

服务索引是一个 JSON 文档,它是 NuGet 包源的入口点,允许客户端实现发现包源的功能。 服务索引是一个具有两个必需属性的 JSON 对象:version(服务索引的架构版本)和 resources(包源的终结点或功能)。

nuget.org 的服务索引位于 https://api.nuget.org/v3/index.json

版本控制

version 值是一个 SemVer 2.0.0 可分析版本字符串,它指示服务索引的架构版本。 API 要求版本字符串的主版本号为 3。 由于对服务索引架构进行了非中断性变更,版本字符串的次要版本将增加。

服务索引中的每个资源是独立于服务索引架构版本进行版本控制的。

当前架构版本为 3.0.03.0.0 版本在功能上等同于较早的 3.0.0-beta.1 版本,但应首选此版本,因为它更清晰地传达了已定义的稳定架构。

HTTP 方法

可以使用 HTTP 方法 GETHEAD 访问服务索引。

资源

resources 属性包含此包源支持的资源数组。

资源

资源是 resources 数组中的一个对象。 它表示包源的版本控制功能。 资源具有以下属性:

名称 类型​​ 必须 注释
@id string 资源的 URL
@type string 一个表示资源类型的字符串常数
评论 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."
    }
  ]
}