Skip to content
Go to file

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time


Make your API self documenting and your clients adaptable to API changes. It's all in the hypermedia type.

Jiron is a hypermedia type based on Siren and the Jade template language. Instead of delivering your data in JSON messages, pack that data with related links, actions that clients can request on the reperesented resource, even code on demand to upgrade the client's capabilities to deal with the given resource.

Jiron: Part or small portion of a whole: patch of fog.


Just an idea for mapping Siren semantics to HTML as opposed to JSON for an enhanced API data delivery experience, explored briefly in the book, "Programming JavaScript Applications".


APIs are becoming crucially important to application development, but there are a few problems with the current state of types used for APIs:

JSON troubles

JSON is a defacto standard format for types, and the syntax is terse, but:

  1. It meets very few requirements for proper hypermedia support.
  2. What few hypermedia types for JSON that do exist tend to have far fewer affordances than HTML.

HTML troubles

HTML is the most popular hypermedia type in the world, but:

  1. We take it for granted as a markup language for UI. It's hard to imagine how to apply it to good API design.
  2. There are no popular standards or implementations of HTML as an API type.
  3. HTML is verbose, and expensive over the network compared to JSON.

Siren troubles

Siren is an elegant way to add hypermedia semantics to JSON, including:

  • Links and relations
  • Entities with classes
  • Actions with templates
  • Metadata

The thing that makes Siren great is that it defines a set of semantics that revolve around the concept of entities -- which happen to map really well to resource representations. Put Siren semantics on top of a resourceful API, and you've got a recipe for a highly scalable, highly decoupled architecture.

Even with the extra affordances that Siren provides, it is still not as rich as HTML in what you can express with it. In particular, it lacks:

  • Code on demand
  • Style support


Jade is a very terse, elegant markup syntax that was originally designed as a template language that compiles to HTML. One day as I was contemplating the problems we have with our current breed of hypermedia types, it occurred to me that Jade might be a great format to base a new type on.

Some things it has going for it:

  • Supports all the features of HTML
  • Light weight syntax
  • Easy to learn
  • Since it's a template language, it's trivial to create serializers for it
  • Since it outputs HTML, it's easy to work with in browsers


  • No clear standard for representing server resources and entities
  • It has the same shortcomings as HTML


What we need is a best of all worlds. Something terse like JSON, but expressive like HTML. A clear way of representing resources and entities. Bonus if we can take advantage of lots of existing tooling in the process.


Jiron is a mapping of Siren semantics combined with the expressive power and affordances of HTML, with the slick syntax of Jade.

Here's a sample:

  title Albums
  h1.title Albums
      p.description A list of albums you should listen to.
      // A count of the total number of entities
      // available. Useful for paging info.
      label(for="entityCount") Total count: 
      span.entityCount(id="entityCount") 3

      a(rel='item', href='/albums/a65x0qxr')
 Dark Side of the Moon
 Pink Floyd
      a(rel='item', href='/albums/a7ff1qxw')
 Random Access Memories
 Daft Punk

      a(rel='next', href='/albums?offset=2&limit=1') Next
      link(rel='self, canonical', href='')

And the equivalent HTML:

<head profile="">

<body class="albums">
    <h1 class="title">Albums</h1>

    <ul class="properties">
        <li class="property">
            <p class="description">A list of albums you should listen to.</p>

        <li class="property"><!-- A count of the total number of entities-->
        <!-- available. Useful for paging info.-->
        <label for="entityCount">Total count:</label> <span class="entityCount"

    <ul class="entities">
        <li class="entity album">
            <a href="/albums/a65x0qxr" rel="item">
            <ul class="properties">
                <li class="property name">Dark Side of the Moon</li>

                <li class="property artist">Pink Floyd</li>

        <li class="entity album">
            <a href="/albums/a7ff1qxw" rel="item">
            <ul class="properties">
                <li class="property name">Random Access Memories</li>

                <li class="property artist">Daft Punk</li>

    <ul class="links">
        <li class="link">
            <a href="/albums?offset=2&amp;limit=1" rel="next">Next</a>

        <li class="link">
            <link href="" rel="self, canonical">

Here's a translation of the example from the Siren README:

  title Order
  h1 Order
      label Order Number
        span.orderNumber 42
      label Item Count
        span.itemCount 3
      label Status
        span.status pending

        | Items

            label Customer ID
              span.customerId pj123

            label Name
     Peter Joseph

      // Action is one of:
      // index, create, show, put, delete, patch
      // The method in html is determined by the
      // mapping between actions and HTML methods.
          legend Add Item
          label Order Number
            input(name='orderNumber', hidden='hidden', value='42')
          label Product Code
            input(name='productCode', type='text')
          label Quantity
            input(name='quantity', type='number')

    a(rel='self', href='',
      style='display: none;')
    a(rel='previous', href='') Previous
    a(rel='next', href='') Next

Which translates to the following HTML:


<body class="order">

    <ul class="properties">
        <li class="property"><label>Order Number<span class=

        <li class="property"><label>Item Count<span class=

        <li class="property"><label>Status<span class=

    <ul class="entities">
        <li class="entity items collection">
            <a href="" rel=

        <li class="entity info customer">
            <a href="" rel=

            <ul class="properties">
                <li class="property"><label>Customer ID<span class=

                <li class="property"><label>Name<span class="name">Peter

    <ul class="actions">
        <li class="action">
            <!-- Action is one of:-->
            <!-- index, create, show, put, delete, patch-->
            <!-- The method in html is determined by the-->
            <!-- mapping between actions and HTML methods.-->

            <form method="POST" action=""
                    <legend>Add Item</legend> <label>Order Number
                    <input hidden="hidden" name="orderNumber" value=
                    "42"></label> <label>Product Code <input name="productCode"
                    type="text"></label> <label>Quantity <input name="quantity"

    <div class="links" style="margin-left: 2em">
        <a href="" rel="self" style=
        "display: none;"></a><a href="" rel=
        "previous">Previous</a><a href="" rel=

Since jiron+jade is based on an existing HTML template syntax, the documents are easy to interpret. Browserify users get support on the client side automatically using You can also use browserify to export an AMD module or stand-alone module for the browser.

Using it in the browser is simple:

jade.render('a.album(href="/albums/123") Pretty Hate Machine');

Which creates the string:

<a href="/albums/123" class="album">Pretty Hate Machine</a>

Now you can add that to a documentFragment and use CSS selectors to query it. Better yet -- just slap some CSS on it and render it as-is. Try that with JSON.

Cool party tricks

Here are some cool things you can do with Jiron that you can't do with JSON:

  • Deliver code on demand with JavaScript links (including any client SDK you need to customize any Jiron browser for your particular API)
  • Deliver default templates that make browsing your API directly in a browser pleasant
  • Deliver clickable links and usable forms while your users are browsing the API directly
  • Use CSS for styling default views
  • Intersperse human-readable text and media with hypertext controls and affordances -- like HTML, only structured specifically for APIs

Tricky with HTML:

  • Support any HTTP method type. PUT, PATCH, DELETE? No problem.
  • Support HTTP header changes in links:

Method types

Jiron is purposely very similar to HTML, except where HTML falls short on important affordances. For example, HTML lacks support for important methods, and doesn't prescribe any mapping between intended actions and HTTP method. HTML is also a little inconsistent with the URL for form targets, calling it action instead of href (which is used in almost all other cases involving links). Jiron can improve on HTML on both counts. Imagine this syntax:


Which would map to the following raw (broken) HTML:

<form action="create" href="" type="application/x-www-form-urlencoded"></form>

And finally be translated to this by the Jiron client:

<form method="POST" action="" type="application/x-www-form-urlencoded"></form>

Support for headers in links:

a(headers='Accept:application/vnd.jiron+jade') Some Jiron resource

Which would translate to this, if HTML knew how to deal with it:

<a headers="Accept:application/vnd.jiron+jade">Some Jiron resource</a>

The Jiron client will attach a link activation handler that will set the appropriate accept header and fetch the resource using AJAX.


Make your API self documenting and your clients adaptable to API changes.




No releases published


No packages published
You can’t perform that action at this time.