I have setup a Nuget.Server to host a private nuget feed. I am trying to access that feed via the API however I can't convince it to give me json instead of XML.
My client code is as follows:
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var packagesResult = client.GetAsync("http://localhost:61654/nuget/FindPackagesById()?id=\'Moq'").Result;
Console.WriteLine(packagesResult.Content.ReadAsStringAsync().Result);
I have checked the Formatters from the App_Start
GlobalConfiguration.Configuration.Formatters
There are four formatters and the frist one is json.
How can I get the API to return json instead of XML?
Nothing wrong with your code. But, it seems that you are calling Nuget API V2 that only supports XML. You can check the response content type.
Content-Type: application/atom+xml; type=feed; charset=utf-8
If you'd like to get the API to return JSON instead of XML, use Nuget API V3.
API definition: https://api.nuget.org/v3/index.json
Sample: https://api.nuget.org/v3/registration3/moq/index.json