nested

command
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: May 20, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

README

Nested Example

This implements an API where the root resource is an Artist which can have Albums and MusicVideos. Then, Albums can have Songs.

It demonstrates:

  • APIs with nested/related resources
  • Custom ResponseWrapper which allows a Song response to show Album details
  • extensions.HATEOAS to easily add hypermedia linking to resources so a user can discover Albums by looking at an Artist and then discover Songs for the Album.

Try it out!

Run the server

go run main.go serve

Create an Artist

⟩ go run main.go client \
  artists post \
  --data '{"name":"artist1"}'
{
    "id": "coinqaon1e4crs6ambu0",
    "links": {
        "Albums": "/artists/coinqaon1e4crs6ambu0/albums",
        "self": "/artists/coinqaon1e4crs6ambu0"
    },
    "name": "artist1"
}

Create an Album

⟩ go run main.go client \
  albums post \
  --artists-id coinqaon1e4crs6ambu0 \
  --data '{"title":"album1"}'
{
    "id": "coinqq8n1e4crs6ambug",
    "links": {
        "Songs": "/artists/coinqaon1e4crs6ambu0/albums/coinqq8n1e4crs6ambug/songs",
        "self": "/artists/coinqaon1e4crs6ambu0/albums/coinqq8n1e4crs6ambug"
    },
    "title": "album1"
}

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

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