Automatic link collection generation for Web API
C# JavaScript CSS ASP
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Automatic link collection generation for ASP.NET Web API + JSON.NET


An add-on for Web API that automatically adds a _links property to JSON objects as they are serialized, based on Route information from the application.


Set up Linky like this:

    public static class WebApiConfig
        public static void Register(HttpConfiguration config)
            // Web API configuration and services

            // Web API routes


Change the property name:

LinkyConfiguration.Configure(config, propName: "_myLinks");

Given this controller with the LinksFrom attribute on the Get(int id) action...

    public class ShipsController : ApiController
        public IEnumerable<Ship> Get()
            return new[] {
                new Ship {Id = 1, Name = "Millennium Falcon"}, 
                new Ship {Id = 42, Name = "Heart of Gold"}};

        [LinksFrom(typeof (Ship), "self")]
        public Ship Get(int id)
            return id == 1
                ? new Ship {Id = 1, Name = "Millennium Falcon"}
                : id == 42
                    ? new Ship {Id = 42, Name = "Heart of Gold"}
                    : null;

... Linky augments the JSON (created by JSON.NET) like this:

        "Id": 1,
        "Name": "Millennium Falcon",
        "_links": {
            "self": "/api/ships/1"
    }, {
        "Id": 42,
        "Name": "Heart of Gold",
        "_links": {
            "self": "/api/ships/42"


This is the first cut of code, hacked together to get something working. It works with the basic use case as shown here, but needs work to bring it up to par with the equivalent functionality found in Simple.Web.


(Forks and Pull Requests appreciated)

  • Configuration
    • Allow customization of the JSON output formatting
    • Allow override of the Route URI template in the LinksFrom attribute
    • Add a QueryString property to the LinksFrom attribute to allow parameters to be added to the URI
  • Tests
  • Performance
    • Currently reflecting on every Request, better to use runtime code-gen.
  • Publish on NuGet


Released under the MIT license. © Copyright Zudio Cloud Tech 2014