/HalKit

A lightweight .NET library for creating and consuming HAL hypermedia APIs

Primary LanguageC#MIT LicenseMIT

HalKit - HAL API Client & Server Library for .NET

NuGet version Downloads Build status

HalKit is a lightweight library, targeting .NET 4.5 and above, that provides an easy way to interact with HAL hypermedia APIs.

Getting Started

HalKit is available on NuGet.

Install-Package HalKit

Usage

Create models for API resources.

public class RootResource : Resource
{
    // Use RelAttribute to (de)serialize links
    [Rel("ea:orders")]
    public Link OrdersLink { get; set; }
}

public class OrdersResource : Resource
{
    // Use the EmbeddedAttribute to (de)serialize embedded resources
    [Embedded("ea:order")]
    IList<OrderResource> Orders { get; set; }
}

public class OrderResource : Resource
{
    public string Status { get; set; }

    [Rel("ea:customer")]
    public Link CustomerLink { get; set; }
}

Clients can use a HalClient to access resources.

var api = new HalClient(new HalKitConfiguration("http://orders-api.com"));
var root = await api.GetRootAsync<RootResource>();

// Use the HalClient to follow hypermedia links
var ordersResource = await api.GetAsync<OrdersResource>(root.OrdersLink);
foreach (var order in ordersResource.Orders)
{
    Console.WriteLine(order.Status);
}

Supported Platforms

  • .NET 4.5 (Desktop / Server)
  • Windows 8 / 8.1 Store Apps
  • Windows Phone 8 / 8.1
  • Xamarin.iOS / Xamarin.Android / Xamarin.Mac
  • Mono 3.x

How to contribute

All submissions are welcome. Fork the repository, read the rest of this README file and make some changes. Once you're done with your changes send a pull request. Thanks!

Need Help? Found a bug?

Just [submit a issue][submitanissue] if you need any help. And, of course, feel free to submit pull requests with bug fixes or changes.