JsonHCS (Json Http Client Simplified) for .Net is a HTTP Client wrapper with Json support. JSON parsing is done by the Newtonsoft.Json library.
JsonHCS.Proxies can interpret a class with requests and responses on the fly for even easier API management: For more info about Json.Net.Proxies visit this page.
Supported platforms: .Net Standard 1.1+
Supported requests:
- GET
- POST
- PUT
- DELETE
- File Download + Upload
-
Include the package in NuGet: https://www.nuget.org/packages/JsonHCS.Net/
-
Add the right usings
using JsonHCSNet;
- Construct with your preferred options
var settings = new JsonHCS_Settings()
{
CookieSupport = true, //I want to support sessions and thus cookies
AddDefaultAcceptHeaders = true, //Adds default acceptance headers for json types
UserAgent = "MyAwesomeSampleAgent" //Because why not, this is usually ignored anyways
};
using (JsonHCS client = new JsonHCS(settings))
{
//use client
}
- Use it!
//Use POCO's for data:
Console.WriteLine("Get<ExpectedResponce> ToString:");
ExpectedResponce obj = await client.GetJsonAsync<ExpectedResponce>(Url); //Gets json from url and parses as the ExpectedResponce class
Console.WriteLine(obj);
///Use dynamic
dynamic obj = await client.GetJsonAsync(Url);
Console.WriteLine(obj.firstName);
//Use JObject
var JObj = await client.GetJObjectAsync(Url);
Console.WriteLine(JObj["firstName"]);
A more complete sample can be found in the source.