Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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