v2.2.1+incompatible Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: Apr 12, 2015 License: MIT, MIT Imports: 4 Imported by: 0



Package hypermedia provides helpers for parsing hypermedia links in resources and expanding the links to make further requests.



This section is empty.


This section is empty.


This section is empty.


type HALResource

type HALResource struct {
	Links Links `json:"_links"`
	// contains filtered or unexported fields

HALResource is a resource with hypermedia specified as JSON HAL.


func (*HALResource) Rels

func (r *HALResource) Rels() Relations

Rels gets the link relations from the HALResource's Links field.

type Hyperlink string

Hyperlink is a string url. If it is a uri template, it can be converted to a full URL with Expand().

func (Hyperlink) Expand

func (l Hyperlink) Expand(m M) (*url.URL, error)

Expand converts a uri template into a url.URL using the given M map.

type HypermediaResource

type HypermediaResource interface {
	Rels() Relations

A HypermediaResource has link relations for next actions of a resource.

type Link struct {
	Href Hyperlink `json:"href"`

Link represents a single link in a HALResource.

func (*Link) Expand

func (l *Link) Expand(m M) (*url.URL, error)

Expand converts a uri template into a url.URL using the given M map.

type Links map[string]Link

Links is a collection of Link objects in a HALResource. Note that the HAL spec allows single link objects or an array of link objects. Sawyer currently only supports single link objects.

type M

type M map[string]interface{}

M represents a map of values to expand a Hyperlink.

type Relations

type Relations map[string]Hyperlink

Relations is a map of keys that point to Hyperlink objects.

func HyperFieldDecoder

func HyperFieldDecoder(res interface{}) Relations

The HyperFieldDecoder gets link relations from a resource by reflecting on its Hyperlink properties. The relation name is taken either from the name of the field, or a "rel" struct tag.

type Foo struct {
  Url         Hyperlink `rel:"self" json:"url"`
  CommentsUrl Hyperlink `rel:"comments" json:"comments_url"`

func HypermediaDecoder

func HypermediaDecoder(res HypermediaResource) Relations

The HypermediaDecoder gets the link relations from any HypermediaResource.

func (Relations) Rel

func (h Relations) Rel(name string, m M) (*url.URL, error)

Rel fetches and expands the Hyperlink by its given key in the Relations map.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL