mattiasnordqvist / Web-Anchor

Web Anchor provides type-safe, testable and flexible, runtime-generated access to web resources.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Web Anchor

.NET Core Codacy Badge Coverage Status All Contributors NuGet version
Web Anchor provides type-safe, testable and flexible, runtime-generated access to web resources.

Install

To install Web Anchor, run the following command in the Package Manager Console

PM> Install-Package WebAnchor

Use

[BaseLocation("api/customer")]
public interface ICustomerApi
{
    [Get("{id}")]
    Task<Customer> GetCustomer(int id);
}

....

var customerApi = Api.For<ICustomerApi>("http://localhost:1111/");
await customerApi.GetCustomer(9);

// => HTTP GET http://localhost:1111/api/customer/9

Does this get you started? Head over to the wiki for more coolness.

Collaborate

Web Anchor is open-sourced to the max and free to use and modify, even for commercial projects. We would love to hear from you if you're using Web Anchor.

Also, if you like (or hate) Web Anchor so much that you would like to contribute in any way, please visit us on GitHub. :)

Alternatives

Although Web Anchor is off course the best framework for accessing web apis, there are alternatives in the .Net ecosystem you might be interested in. Web Anchor is more or less inspired by ReFit. ReFit uses a completely different approach on how the implementation of your api interfaces is created. While Web Anchor generates an implementation in runtime using Castle Windsor DynamicProxy (which means Web Anchor won't work in code distributed through the Windows Phone App Store or whatever it is called), ReFit generates code at compile time. There is also RestSharp which I have never tried. It seems to work in a very different way from both ReFit and Web Anchor and it doesn't look extensible at all! (restsharp/RestSharp#932)

Caveats

When working with HttpClient in any way, you should know some things. Read up on how the HttpClient works and how it is intended to be used, because your intuition is probably wrong.
http://aspnetmonsters.com/2016/08/2016-08-27-httpclientwrong/
http://byterot.blogspot.se/2016/07/singleton-httpclient-dns.html

Contributors

Thanks goes to these wonderful people (emoji key):


Carl Berg

πŸ€” πŸ’» πŸ‘€ πŸ›

Martin Oom

πŸ’»

Mikael Johansson

πŸ›

Mike Goatly

πŸ’» ⚠️

This project follows the all-contributors specification. Contributions of any kind welcome!

About

Web Anchor provides type-safe, testable and flexible, runtime-generated access to web resources.

License:MIT License


Languages

Language:C# 97.1%Language:PowerShell 2.9%