Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Build the API First (Rosie Hoyem and Sonja Hall)

Build the API First (Rosie Hoyem and Sonja Hall)

Presented at RailsConf 2014.

The next five years of web development are all about data applications and APIs. Learn why it is useful to leverage Rails-API to build them. This modular subset of a normal Rails application streamlines the process of building a standardized API that can easily be consumed by a wide-array of applications. We’ll explore the approach of 'building the API first' and demonstrate the expanding utility of the Rails-API framework as user interfaces extend beyond HTML into native applications and APIs.

Avatar for Sonja Hall

Sonja Hall

April 24, 2014
Tweet

Other Decks in Technology

Transcript

  1. BUILD THE FIRST Sonja Hall @sonjahall Washington, DC Web Design

    Engineer, Venga Rosie Hoyem @rhoyem Minneapolis, MN Developer, Minnesota Population Center
  2. OVERVIEW nigesecurityguy.wordpress.com Intro: Patterns that Support Good Design 1. Why

    Build the API First 2. API Best Practices 3. Why Use Rails to Build an API
  3. REST SERVER + JAVASCRIPT FRAMEWORK Use the same API to

    send data to a Javascript client.
  4. WHY BUILD THE API FIRST? 1. Your application can easily

    pass around data. 2. Minimal duplication across platforms. 3. Standardized server code promotes standardized client code.
  5. THE LIFE SPAN OF AN API Version your APIs (and

    plan for deprecation from version ONE)
  6. JSON STANDARDS: jsonapi.org “By following shared conventions, you can increase

    productivity, take advantage of generalized tooling, and focus on what matters: your application.” - STEVE KLABNIK
  7. TOOLS SINATRA RAILS-API RAILS ONE OF 14 OPTIONS ON RUBY

    TOOLBOX HAND ROLLING YOUR OWN VS VS VS WITH
  8. HANDLED AT THE MIDDLEWARE LAYER: Security: Rails detects and thwarts

    IP spoofing attacks and handles cryptographic signatures in a timing attack aware way.
  9. # app/serializers/users class UserSerializer < ActiveModel::Serializer attributes :id, :username, :email,

    :url has_many :list_items def url user_url(object) end end SERIALIZERS
  10. { user: { id: 1, username: "TestUserOne!", email: "[email protected]", url:

    "http://localhost:3000/users/1", list_items: [ { id: 1, content: "Learn to Code", user_id: 1 }, { id: 2, content: "Build a house", user_id: 1 } ] } } GET /users/1
  11. This is a fundamental view of the world. It says

    that when you build a thing you cannot merely build that thing in isolation, but must repair the world around it, and within it, so that the larger world at that one place becomes more coherent, and more whole; and the thing which you make takes its place in the web of nature, as you make it. ~ Christopher Alexander
  12. RESOURCES: Code & Tools BUCKETLIZTR API: https://github.com/rosiehoyem/rails-api-bucketliztr RAILS-API: https://github.com/rails-api/rails-api ACTIVE

    MODELSERIALIZERS: https://github.com/rails- api/active_model_serializers APIARY: http://apiary.io/ FDOC: https://github.com/square/fdoc RUBY TOOLBOX, API BUILDERS:: https://www.ruby-toolbox. com/categories/API_Builders
  13. RESOURCES: Railscasts Rails-api: http://railscasts.com/episodes/348-the-rails-api-gem ActiveModel::Serializers: http://railscasts.com/episodes/409-active-model- serializers Rails API versioning:

    http://railscasts.com/episodes/350-rest-api-versioning Middleware: http://railscasts.com/episodes/319-rails-middleware-walkthrough
  14. RESOURCES: RailsConf Talks Yahuda Katz, Rails: The Next Five Years::

    http://www.confreaks. com/videos/907-railsconf2012-rails-the-next-five-years Noel Rapin, Rails vs. the Client Side: http://www.confreaks. com/videos/2447-railsconf2013-rails-vs-the-client-side