August 24, 2014

Building Generic HAL Browser

At work, I wanted to browse our Hypermedia API, but also wanted to play with how we could generate a generic HAL browser. It wasn’t too crazy but here is some of the things I found.

The biggest problem with Hypermedia API’s is the tooling. Now, you could just use a REST client, but that may not help you be able to build something in your language of choice. Mine happens to be C#. I have seen some of the HAL libraries out there for C#, but they weren’t that great. That may have changed, but I wanted to go about making one myself.

The biggest thing I discovered is that dictionaries are one of the only ways to encapsulate the logic that you may want. Here is what I created for a HAL response:

 public class HalObject { public HalObject(IDictionary<string, string> dataProperties, IDictionary<string, IList> embeddedResources, IDictionary<string, IList> links) { DataProperties = dataProperties; EmbeddedResources = embeddedResources; Links = links; } public IDictionary<string, string> DataProperties { get; private set; } public IDictionary<string, IList> EmbeddedResources { get; private set; } public IDictionary<string, IList> Links { get; private set; } } </pre> 

A HAL response is pretty standard, a section for your data, a set of embedded resources and a list of links.

Once I got it going, I used my api at /api, and was able to get feedback from dog fooding that. Next, I’ll be going to work to see how well it plays there. If you want to use the browser, you can get it from my git repo at: http://github.com/supermitsuba/GenericHalBrowser

I’ll probably build some more tooling around it, as it can only handle GET requests, and no options for templated query string parameters. If you have suggestions, questions or comments, please feel free to add a comment.