Use the space bar or arrow keys to browse the slide.

Some of the images are pretty big, so if you see an empty slide then wait a bit.

Yaks

 

ROSSConf

25 April 2015

Arne Brasseur

What is it?

What is it

A library for building APIs

It serializes objects

It’s specialized in Hypermedia

customer = Customer.find(27)
yaks = Yaks.new

json = yaks.call(
  customer,
  mapper: CustomerMapper,
  env: rack_env
)
class CustomerMapper < Yaks::Mapper
  attributes :first_name, :last_name, :age

  def age
    Date.today - customer.date_of_birth
  end

  link :self,   '/api/customer/{id}'
  link :orders, '/api/customer/{id}/orders',
    if: -> { is_logged_in_customer? }
end

Three main name spaces

Yaks::Mapper*
Yaks::Resource*
Yaks::Format*

Very flexible and configurable

Central representation Yaks::Resource

Yaks::Resource.new(
  type: "customer",
  attributes: {
    first_name: "Arne",
    last_name: "Brasseur"
  },
  links: [
    Yaks::Resource::Link.new(rel: :self, uri: "/customer/5")
  ],
  forms: [
    Yaks::Resource::Form.new(...)
  ]
)

Turned into many output formats: HAL, JSON API, Collection+JSON, HTML, HALO, Transit

DEMO

Why?

Why I built Yaks

Building hypermedia API + Ember app for Ticketsolve

No existing libraries fitted the bill

Developing in the open would improve quality

Community

Community

Still young, small but friendly

Github issues, Gitter chat

Main contributions: improvements to specific formats

How to contribute?

How to contribute?

Use it! report back!

Scratch your own itch

Coding and non-coding skills needed

What’s happening?

What’s happening?

Recent focus: improving mutation coverage

Improve support for various formats

Better docs, examples

This afternoon

Several issues marked ROSSConf
or Beginner Friendly in Github

Improve HTML output

Ruby / HTML / CSS task

Fun task because creative and immediate feedback

Check the README with Ataru

Tests code examples in documentation

8 out of 30 currently fail

Cool because you learn a useful new tool

Shorthand attribute syntax

Turn this

class FooMapper < Yaks::Mapper
  attributes :bar

  def bar
    object.baz
  end
end

into

class FooMapper < Yaks::Mapper
  attribute :bar do
    object.baz
  end
end

Support for Siren

JSON-based format that’s becoming popular

Maps very well to Yaks’s abstractions

Great for learning about how Yaks works