James Ko James Ko - 10 months ago 79
C# Question

Where can I find documentation for the NuGet v3 API?

I'm interested in writing a client library around the NuGet v3 API in a non-.NET language. Where can I find documentation/resources on it that would tell me e.g. what URLs to make requests to and what responses it would return?

I tried doing a quick Google search, but the only thing that turns up is this, which was last updated 3 years ago. Does a spec exist?

Answer Source

Right now we don't have any public documentation, and in fact we are evolving the protocol to make it faster for scenarios like search, UI presentation and updating packages.

Here is a small intro

The protocol is really a host of multiple protocols described by the https://api.nuget.org/v3/index.json, and has a few major components

  1. The service index (the URL above)
  2. The search service - The ability to take a package id or a search term, and get links to packages
  3. Registration - A json-LD based structure allowing accessing an expanded information about package content, dependencies, descriptions etc.
  4. PackageBaseAddress - A simple "disk" like mechanism allowing access to nuspec, nupkg and sha as well as a list of versions (described in the index document)

We do plan to officially document the protocol once is becomes more stable. Depending one what parts of the protocol you are trying to implement, you want to look at the repos in https://github.com/nuget/nuget.client. The protocol projects are just bits and pieces, You want to start from the nuget.commandline and walk your way down the stack.

As a very simple example (downloading a package given a known id): Get the service index (https://api.nuget.org/v3/index.json)

snippet of the response:

  "@id": "https://api.nuget.org/v3-flatcontainer/",
  "@type": "PackageBaseAddress/3.0.0",
  "comment": "Base URL of Azure storage where NuGet package registration info for DNX is stored, in the format https://api.nuget.org/v3-flatcontainer/{id-lower}/{version-lower}.{version-lower}.nupkg"

Download the package: GET https://api.nuget.org/v3-flatcontainer/newtonsoft.json/6.0.4/newtonsoft.json.6.0.4.nupkg

Download the list of all versions GET https://api.nuget.org/v3-flatcontainer/newtonsoft.json/index.json