Skip to content

RESTful JSON: Adding Links to your APIs

Sponsor: Do you build complex software systems? See how NServiceBus makes it easier to design, build, and manage software systems that use message queues to achieve loose coupling. Get started for free.

Learn more about Software Architecture & Design.
Join thousands of developers getting weekly updates to increase your understanding of software architecture and design concepts.


RESTful JSONThere’s a new media type available, RESTful JSON, that was recently registered (Feb 1st 2018) with IANA.  It’s really the simplest possible media type to use in order to start adding links to your JSON APIs.  The new media type is application/vnd.restful+json 

Adding Hyperlinks

The simplicity here is that you can start using this media type with existing APIs to start adding links to your existing objects.
  1. JSON objects MAY include a url property to indicate a link to itself
  2. JSON objects MAY append _url to properties to indicate related links

Example

Here’s an existing payload of a e-commerce shopping cart.  It has one product in the cart.
Now we are going to add a couple links.  We are going to add a link to the product in our cart to the product page, and add another link to provide the URI for the checkout page.

Runtime

Links are to be used at runtime by your client.  Meaning the presents or absence of them will determine how your client behaves.  With links provided in the API, you can now traverse the payload at runtime rather than hardcode URIs. Are you using a hypermedia content type?  I’d love to hear your comments or on Twitter.

Learn more about Software Architecture & Design.
Join thousands of developers getting weekly updates to increase your understanding of software architecture and design concepts.


Leave a Reply

Your email address will not be published. Required fields are marked *