Skip to content

Instantly share code, notes, and snippets.

@oestrich
Last active September 29, 2018 19:04
Show Gist options
  • Save oestrich/5bc9702f8d645670d66c9b948d6bfcc3 to your computer and use it in GitHub Desktop.
Save oestrich/5bc9702f8d645670d66c9b948d6bfcc3 to your computer and use it in GitHub Desktop.
Representers

Representers

Starting data

order = %Order{
  id: 10,
  first_name: "User",
  last_name: "Example",
}

orders = [order]

Item

%Representer.Item{
  rel: "https://example.com/rels/order",
  href: "https://example.com/orders/1",
  data: order,
  links: [
    %Representer.Link{
      rel: "self",
      href: "https://example.com/orders/1"
    },
  ],
}

Collection

%Representer.Collection{
  href: "https://example.com/orders",
  name: "orders",
  items: Enum.map(orders, &item/1),
  links: [
    %Representer.Link{
      rel: "self",
      href: "https://example.com/orders"
    },
    %Representer.Link{
      rel: "up",
      href: "https://example.com/"
    }
  ]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment