Skip to content
This repository has been archived by the owner on Jul 24, 2021. It is now read-only.

jagregory/hypermedia

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

hypermedia

An collection of opinionated hypermedia wrappers. Resources and collections. Useful for decorating arbitrary structs with links.

Install

go get github.com/jagregory/hypermedia

Usage

import (
  hm "github.com/jagregory/hypermedia"
)

Resource:

res := hm.NewResource(product, hm.Selff("/products/%d", product.Id))

JSON:

{
  "links": {
    "self": { "href": "/products/123" }
  },
  "entity": {
    "id": "123",
    "name": "Soap"
  }
}

Collection:

col := hm.NewCollection(
  []hm.Resource{
    hm.NewResource(product, hm.Selff("/products/%d", product.Id)),
  },
  hm.Self("/archive/2"),
  hm.Linkf("next", "/archive/3"),
  hm.Linkf("prev", "/archive/1"),
)

JSON:

{
  "link": {
    "self": { "href": "/archive/2" },
    "next": { "href": "/archive/3" },
    "prev": { "href": "/archive/1" }
  },
  "collection": [
    {
      "links": {
        "self": { "href": "/products/123" }
      },
      "entity": {
        "id": "123",
        "name": "Soap"
      }
    }
  ]
}

About

Opinionated hypermedia helpers

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages