Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/mattiasnordqvist/Web-Anchor

Web Anchor provides type-safe, testable and flexible, runtime-generated access to web resources.
https://github.com/mattiasnordqvist/Web-Anchor

api-client c-sharp httpclient json

Last synced: about 2 months ago
JSON representation

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

Awesome Lists containing this project

README

        

# Web Anchor
![.NET Core](https://github.com/mattiasnordqvist/Web-Anchor/workflows/.NET%20Core/badge.svg?branch=master)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/b1413bab9e9d4ee0b2a9d329b395b1a8)](https://app.codacy.com/manual/mattiasnordqvist/Web-Anchor?utm_source=github.com&utm_medium=referral&utm_content=mattiasnordqvist/Web-Anchor&utm_campaign=Badge_Grade_Dashboard)
[![Coverage Status](https://coveralls.io/repos/github/mattiasnordqvist/Web-Anchor/badge.svg?branch=master)](https://coveralls.io/github/mattiasnordqvist/Web-Anchor?branch=master)
[![All Contributors](https://img.shields.io/badge/all_contributors-4-orange.svg?style=flat-square)](#contributors)
[![NuGet version](https://badge.fury.io/nu/webanchor.svg)](http://badge.fury.io/nu/webanchor)
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](http://docs.nuget.org/docs/start-here/using-the-package-manager-console)

PM> Install-Package WebAnchor

## Use
```csharp
[BaseLocation("api/customer")]
public interface ICustomerApi
{
[Get("{id}")]
Task GetCustomer(int id);
}

....

var customerApi = Api.For("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](https://github.com/mattiasnordqvist/Web-Anchor/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](https://github.com/mattiasnordqvist/Web-Anchor). :)

## 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](https://github.com/paulcbetts/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](http://restsharp.org/) 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! (https://github.com/restsharp/RestSharp/issues/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](https://allcontributors.org/docs/en/emoji-key)):



Carl Berg

🤔 💻 👀 🐛

Martin Oom

💻

Mikael Johansson

🐛

Mike Goatly

💻 ⚠️

This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!