hypermedia

package
Version: v0.0.0-...-0b59bd9 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2014 License: MIT Imports: 6 Imported by: 23

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FillRels

func FillRels(resource interface{}, rels Relations)

FillRels populates the given relations object from the relations in the resource.

Types

type CachedResource

type CachedResource interface {
	Rels() (Relations, bool)
	CacheRels(Relations)
}

A CachedResource is capable of caching the relations locally, so that multiple accesses don't require parsing it again.

type HALResource

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

HALResource is a resource with hypermedia specified as JSON HAL.

http://stateless.co/hal_specification.html

func (*HALResource) HypermediaRels

func (r *HALResource) HypermediaRels(rels Relations)

HypermediaRels implements the HypermediaResource interface by getting the Relations from the Links property.

type HyperfieldResource

type HyperfieldResource interface {
	HyperfieldRels()
}
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 {
	HypermediaRels(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 HyperFieldRelations

func HyperFieldRelations(res interface{}, rels Relations) Relations

The HyperFieldRelations 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 HyperHeaderRelations

func HyperHeaderRelations(header http.Header, rels Relations) Relations

TODO: need a full link header parser for http://tools.ietf.org/html/rfc5988

func NewRels

func NewRels() Relations

Rels returns a new Relations object.

func Rels

func Rels(resource interface{}) Relations

Rels gets the hypermedia relations from the given resource.

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