go-sawyer: github.com/lostisland/go-sawyer/hypermedia Index | Files

package hypermedia

import "github.com/lostisland/go-sawyer/hypermedia"

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

Index

Package Files

hal.go hyperfields.go hyperheaders.go hypermedia.go

func FillRels Uses

func FillRels(resource interface{}, rels Relations)

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

type CachedResource Uses

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 Uses

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 Uses

func (r *HALResource) HypermediaRels(rels Relations)

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

type HyperfieldResource Uses

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 Uses

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 Uses

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 Uses

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 Uses

type M map[string]interface{}

M represents a map of values to expand a Hyperlink.

type Relations Uses

type Relations map[string]Hyperlink

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

func HyperFieldRelations Uses

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 Uses

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

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

func NewRels Uses

func NewRels() Relations

Rels returns a new Relations object.

func Rels Uses

func Rels(resource interface{}) Relations

Rels gets the hypermedia relations from the given resource.

func (Relations) Rel Uses

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.

Package hypermedia imports 6 packages (graph) and is imported by 6 packages. Updated 2016-07-21. Refresh now. Tools for package owners.