hateoas

package
v0.0.0-...-c126cd1 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2017 License: BSD-3-Clause Imports: 8 Imported by: 4

README

hateoas

import "github.com/CreatorKit/go-deviceserver-client/hateoas"

Overview

Generic-ish HATEOAS client for golang

Index

Package files

hateoas.go

Variables

var (
    ErrorLinkNotFound = errors.New("Link not found")
    ErrorHttpStatus   = errors.New("HTTP status error")
    ErrorBadConfig    = errors.New("bad config")
)

type Client

type Client struct {
    EntryURL       string
    DefaultHeaders Headers
    Http           HTTPDoer
}

Client is the main object for executing requests

func Create
func Create(config *Client) *Client

Create will populate some defaults into a provided Client structure

func (*Client) Delete
func (c *Client) Delete(url string, navigateLinks Navigate, headers Headers, body io.Reader, response interface{}) (*http.Response, error)

Delete is a small wrapper around Do

func (*Client) Do
func (c *Client) Do(method string, url string, navigateLinks Navigate, headers Headers, body io.Reader, result interface{}) (*http.Response, error)

Do will start at the provided URL (or default to Client.EntryURL) and traverse the links specified by navigateLinks (with GET) before finally issuing method to the resultant URL

func (*Client) Get
func (c *Client) Get(url string, navigateLinks Navigate, headers Headers, body io.Reader, response interface{}) (*http.Response, error)

Get is a small wrapper around Do

func (*Client) Post
func (c *Client) Post(url string, navigateLinks Navigate, headers Headers, body io.Reader, response interface{}) (*http.Response, error)

Post is a small wrapper around Do

func (*Client) PostForm
func (c *Client) PostForm(url string, navigateLinks Navigate, headers Headers, data url.Values, response interface{}) (*http.Response, error)

PostForm is a small wrapper around Do

type HTTPDoer

type HTTPDoer interface {
    Do(*http.Request) (*http.Response, error)
}

HTTPDoer would normally be an instance of *http.Client but by making it an interface we allow wrapping to permit logging or caching etc

type Headers

type Headers map[string]string

Headers is the HTTP headers to be added to a request

type Link struct {
    Rel  string `json:"rel"`
    Href string `json:"href"`
    Type string `json:"type"`
}

Link is the main HATEOAS link object

type Links []Link

Links is just an array of Link, but with some helper methods

func (l Links) Get(rel string) (*Link, error)

Get returns the link matching the specified rel name

func (l Links) Self() string

Self is a small wrapper around Get, mostly useful when you don't need to worry if the link isn't actually there (e.g. when printing debug stuff to a CLI output)

type Navigate

type Navigate []string

Navigate specifies a list of links to be traversed

type SimpleEndpoint

type SimpleEndpoint struct {
    Links Links `json:"Links"`
}

SimpleEndpoint is used when navigating links on endpoints


Generated by godoc12md

Documentation

Overview

Generic-ish HATEOAS client for golang

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorLinkNotFound = "Link not found"
	ErrorHttpStatus   = "HTTP status error"
	ErrorBadConfig    = "bad config"
)

Functions

This section is empty.

Types

type Client

type Client struct {
	EntryURL       string
	DefaultHeaders Headers
	Http           HTTPDoer
}

Client is the main object for executing requests

func Create

func Create(config *Client) *Client

Create will populate some defaults into a provided Client structure

func (*Client) Delete

func (c *Client) Delete(url string, navigateLinks Navigate, headers Headers, body io.Reader, response interface{}) (*http.Response, error)

Delete is a small wrapper around Do

func (*Client) Do

func (c *Client) Do(method string, url string, navigateLinks Navigate, headers Headers, body io.Reader, result interface{}) (*http.Response, error)

Do will start at the provided URL (or default to `Client.EntryURL`) and traverse the links specified by `navigateLinks` (with GET) before finally issuing `method` to the resultant URL

func (*Client) Get

func (c *Client) Get(url string, navigateLinks Navigate, headers Headers, body io.Reader, response interface{}) (*http.Response, error)

Get is a small wrapper around Do

func (*Client) Post

func (c *Client) Post(url string, navigateLinks Navigate, headers Headers, body io.Reader, response interface{}) (*http.Response, error)

Post is a small wrapper around Do

func (*Client) PostForm

func (c *Client) PostForm(url string, navigateLinks Navigate, headers Headers, data url.Values, response interface{}) (*http.Response, error)

PostForm is a small wrapper around Do

type HTTPDoer

type HTTPDoer interface {
	Do(*http.Request) (*http.Response, error)
}

HTTPDoer would normally be an instance of *http.Client but by making it an interface we allow wrapping to permit logging or caching etc

type Headers

type Headers map[string]string

Headers is the HTTP headers to be added to a request

type Link struct {
	Rel  string `json:"rel"`
	Href string `json:"href"`
	Type string `json:"type"`
}

Link is the main HATEOAS link object

type Links []Link

Links is just an array of Link, but with some helper methods

func (Links) Get

func (l Links) Get(rel string) (*Link, error)

Get returns the link matching the specified `rel` name

func (Links) Self

func (l Links) Self() string

Self is a small wrapper around Get, mostly useful when you don't need to worry if the link isn't actually there (e.g. when printing debug stuff to a CLI output)

func (Links) String

func (l Links) String() string
type Navigate []string

Navigate specifies a list of links to be traversed

type SimpleEndpoint

type SimpleEndpoint struct {
	Links Links `json:"Links"`
}

SimpleEndpoint is used when navigating links on endpoints

Jump to

Keyboard shortcuts

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