Skip to content

dapplo/Dapplo.HttpExtensions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dapplo.httpextensions

  • Documentation here
  • Current build status: Build Status
  • Coverage Status: Coverage Status
  • NuGet package: NuGet package

Sometimes you just want to access a service in the internet or on a local server. This project helps you to deal with a lot of difficult stuff, like having a default proxy or even making a specify proxy possible. Also it can handle Json communication, which a lot of REST based APIs use.

A short example:

	using Dapplo.HttpExtensions;

	var uri = new Uri("http://myserver/");
	var response = await uri.GetAsAsync<string>();

A more "complex" example of how you can use this, is available in the test.

There is a test with calling a JSON Service (GitHub): UriActionExtensionsTests.TestGetAsJsonAsync_GitHubApiReleases.

There is also an OAuth test: OAuth/OAuthTests.TestOAuthHttpMessageHandler. This is not running during the build, as it needs "human" interaction with a browser.

Some of the features:

  1. Fluent API
  2. Progress support, for uploading and downloading
  3. Typed access to Http content (e.g. GetAsAsync )
  4. Typed upload
  5. Json support, in two variants:
  6. SimpleJson via nuget package Dapplo.HttpExtensions.JsonSimple and call SimpleJsonSerializer.RegisterGlobally() or set IHttpBehavior.JsonSerializer to new SimpleJsonSerializer();
  7. install nuget package Dapplo.HttpExtensions.JsonNet and call JsonNetJsonSerializer.RegisterGlobally(); or set IHttpBehavior.JsonSerializer to new JsonNetJsonSerializer();
  8. OAuth 1 & 2 via nuget package Dapplo.HttpExtensions.OAuth, this is currently work in process but with some servers it should already be usable.

Notes: This project uses async code, and tries to conform to the Task-bases Asynchronous Pattern (TAP). Just so you know why sometimes the method name look odd... Meaning all async methods have names which end with Async and (where possible) accept a CancellationToken. This is the final parameter, as adviced here: https://blogs.msdn.microsoft.com/andrewarnottms/2014/03/19/recommended-patterns-for-cancellationtoken/

API Changes, with every 0.x change the signatures have changed: In 0.2.x a HttpBehaviour object was added to prevent future signature changes as much as possible. In 0.3.x a lot of previous method were combined. (GetAsMemoryStream -> GetAsAsync, GetAsStringAsync -> GetAsAsync) In 0.4.x the IHttpBehaviour was removed again, it's now passed via the CallContext. If you need to a specific behaviour for a call, than you will need to call MakeCurrent() on the behaviour before the call. In 0.5.x The configuration logic for the converters was changed In 0.6.x the Json and OAuth support were removed from the main package In 0.7.x doesn't have changes (switched to 0.8 by mistake) In 0.8.x the project / build was changed to use the new csproj, build with VS2017 15.3 (due to csproj limitations in 15.2)

About

.NET extensions for using the HttpClient to call Http(s) services, with less complexity

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Languages