SlideShare a Scribd company logo
Enter the App Era
with Ruby on Rails

     @matteocollina
RubyDay.it
15 June 2012

   www.rubyday.it
Matteo Collina

Software Engineer

@matteocollina

matteocollina.com
www.mavigex.com
   www.wemobi.it
How is built an App?




               http://www.flickr.com/photos/dschulian/3173331821/
Code




       Icons by Fasticon
Code   Run




             Icons by Fasticon
Code   Run   Server




                      Icons by Fasticon
Code   Run   Server




                      Icons by Fasticon
Code   Run   Server




                      Icons by Fasticon
Code   I   need to
           serve
               Run   Server

     my data to
Web and Mobile Apps



                              Icons by Fasticon
We need an API
We need an API


Who has APIs?
Who has APIs?
Who has APIs?
Who has APIs?



And many many others..
We will develop an API
We need to be fast!




               http://www.flickr.com/photos/oneaustin/1261907803
We have just
twenty minutes




          http://www.flickr.com/photos/oneaustin/1261907803
What do we
want to build?   http://www.flickr.com/photos/oberazzi/318947873/
Another tool for nerds?




                          http://www.flickr.com/photos/eyesontheroad/2260731457/
Another Todo List?




                     http://www.flickr.com/photos/eyesontheroad/2260731457/
Enter MCDo.
http://github.com/mcollina/mcdo
Enter MCDo.

The First Todo List
   delivered as
   a REST API
The First Todo List
   delivered as
   a REST API
Signup API
http://github.com/mcollina/mcdo
Signup API
Feature: Signup API
  As a MCDO developer
  In order to develop apps
  I want to register new users

  Scenario: Succesful signup
    When I call "/users.json" in POST with:
      """
      {
        "user": {
          "email": "hello@abc.org",
          "password": "abcde",
          "password_confirmation": "abcde"
        }
      }
      """
    Then the JSON should be:
      """
      {
        "id": 1,
        "email": "hello@abc.org"
      }
      """
Signup API

Scenario: signup fails with a wrong password_confirmation
  When I call "/users.json" in POST with:
    """
    {
      "user": {
        "email": "hello@abc.org",
        "password": "abcde",
        "password_confirmation": "abcde1"
      }
    }
    """
  Then the JSON should be:
    """
    {
      "errors": { "password": ["doesn't match confirmation"] }
    }
    """
How?
How?

Ruby on Rails

Cucumber

RSpec

JSON-spec
How?

       Ruby on Rails


Let’s see some code!
       Cucumber

       RSpec

       JSON-spec
Login API
http://github.com/mcollina/mcdo
Login API
Feature: Login API
  As a MCDO developer
  In order to develop apps
  I want to login with an existing user

  Background:
    Given there is the following user:
      | email       | password | password_confirmation |
      | abcd@org.it | aa       | aa                    |

  Scenario: Succesful login
    When I call "/session.json" in POST with:
      """
      {
        "email": "abcd@org.it",
        "password": "aa"
      }
      """
    Then the JSON should be:
      """
      {
        "status": "authenticated"
      }
      """
Login API
Scenario: Failed login
  When I call "/session.json" in POST with:
    """
    {
      "email": "abcd@org.it",
      "password": "bb"
    }
    """
  Then the JSON should be:
    """
    {
      "status": "not authenticated"
    }
    """
Login API
Scenario: Validating an active session
    Given I call "/session.json" in POST with:
      """
      {
        "email": "abcd@org.it",
        "password": "aa"
      }
      """
    When I call "/session.json" in GET
    Then the JSON should be:
      """
      {
        "status": "authenticated"
      }
      """
Login API
  Scenario: Validating an active session
      Given I call "/session.json" in POST with:
        """
        {
          "email": "abcd@org.it",
          "password": "aa"
        }


Let’s see some code!
        """
      When I call "/session.json" in GET
      Then the JSON should be:
        """
        {
          "status": "authenticated"
        }
        """
Lists API
http://github.com/mcollina/mcdo
Lists API
Feature: Lists API
  As a MCDO developer
  In order to develop apps
  I want to manage a user's lists

  Background:
    Given I login succesfully with user "aaa@abc.org"

  Scenario: Default lists
    When I call "/lists.json" in GET
    Then the JSON should be:
      """
      {
        "lists": [{
           "id": 1,
           "name": "Personal",
           "link": "http://www.example.com/lists/1",
           "items_link": "http://www.example.com/lists/1/items"
        }]
      }
      """
Lists API

Scenario: Creating a list
  When I call "/lists.json" in POST with:
    """
    {
      "list": {
        "name": "foobar"
      }
    }
    """
  Then the JSON should be:
    """
    {
      "name": "foobar",
      "items_link": "http://www.example.com/lists/1/items"
    }
    """
Lists API
Scenario: Creating a list should add it to the index
  Given I call "/lists.json" in POST with:
    """
    {
      "list": {
         "name": "foobar"
      }
    }
    """
  When I call "/lists.json" in GET
  Then the JSON should be:
    """
    {
      "lists": [{
         "id": 2,
         "name": "foobar",
         "link": "http://www.example.com/lists/2",
         "items_link": "http://www.example.com/lists/2/items"
      }, {
         "id": 1,
         "name": "Personal",
         "link": "http://www.example.com/lists/1",
         "items_link": "http://www.example.com/lists/1/items"
      }]
    }
    """
Lists API
Scenario: Removing a list (and the index is empty)
  Given I call "/lists/1.json" in DELETE
  When I call "/lists.json"
  Then the JSON should be:
    """
    {
      "lists": []
    }
    """

Scenario: Updating a list's name
  When I call "/lists/1.json" in PUT with:
    """
    {
      "list": {
        "name": "foobar"
      }
    }
    """
  Then the JSON should be:
    """
    {
      "name": "foobar",
      "items_link": "http://www.example.com/lists/1/items"
    }
    """
Lists API
   Scenario: Removing a list (and the index is empty)
     Given I call "/lists/1.json" in DELETE
     When I call "/lists.json"
     Then the JSON should be:
       """
       {
         "lists": []
       }
       """


Let’s see some code!
   Scenario: Updating a list's name
     When I call "/lists/1.json" in PUT with:
       """
       {
         "list": {
           "name": "foobar"
         }
       }
       """
     Then the JSON should be:
       """
       {
         "name": "foobar",
         "items_link": "http://www.example.com/lists/1/items"
       }
       """
Items API
http://github.com/mcollina/mcdo
Items API
Feature: Manage a list's items
  As a developer
  In order to manipulate the list's item
  I want to access them through APIs

  Background:
    Given I login succesfully with user "aaa@abc.org"

  Scenario: Default items
    When I call "/lists/1/items.json" in GET
    Then the JSON should be:
    """
    {
      "items": [{
        "name": "Insert your items!",
        "position": 0
      }],
      "list_link": "http://www.example.com/lists/1"
    }
    """
Items API
Scenario: Moving an element to the top
  Given I call "/lists/1/items.json" in POST with:
  ...
  And I call "/lists/1/items.json" in POST with:
  ...
  When I call "/lists/1/items/2/move.json" in PUT with:
  """
  {
    "position": 0
  }
  """
  Then the JSON should be:
  """
  {
    "items": [{
      "name": "b",
      "position": 0
    }, {
      "name": "Insert your items!",
      "position": 1
    }, {
      "name": "c",
      "position": 2
    }],
    "list_link": "http://www.example.com/lists/1"
  }
  """
Items API
   Scenario: Moving an element to the top
     Given I call "/lists/1/items.json" in POST with:
     ...
     And I call "/lists/1/items.json" in POST with:
     ...
     When I call "/lists/1/items/2/move.json" in PUT with:
     """
     {
       "position": 0
     }


Let’s see some code!
     """
     Then the JSON should be:
     """
     {
       "items": [{
         "name": "b",
         "position": 0
       }, {
         "name": "Insert your items!",
         "position": 1
       }, {
         "name": "c",
         "position": 2
       }],
       "list_link": "http://www.example.com/lists/1"
     }
     """
Do we need
an admin panel?
Do we need
an admin panel?
Do we need
  an admin panel?
Put in your Gemfile:

  gem 'activeadmin'
  gem 'meta_search', '>= 1.1.0.pre'


Then run:

  $   bundle install
  $   rails g active_admin:install
  $   rails g active_admin:resource users
  $   rails g active_admin:resource lists
  $   rails g active_admin:resource items
  $   rake db:migrate
Do we need
  an admin panel?
Put in your Gemfile:




Let’s see some code!
  gem 'activeadmin'
  gem 'meta_search', '>= 1.1.0.pre'


Then run:

  $   bundle install
  $   rails g active_admin:install
  $   rails g active_admin:resource users
  $   rails g active_admin:resource lists
  $   rails g active_admin:resource items
  $   rake db:migrate
Build a JS App!
Build a JS App!


  Backbone.js: MVC in the browser

  Rails asset pipeline concatenate
and minifies our JS automatically

 We can even write our app in
CoffeeScript: it works out of the box.
Build a JS App!


   Backbone.js: MVC in the browser

to Rails asset pipeline concatenate
    the code.. again?
 and minifies our JS automatically

  We can even write our app in
 CoffeeScript: it works out of the box.
http://www.flickr.com/photos/oneaustin/1261907803
We are late,
   the #codemotion
crew are kicking me out



                 http://www.flickr.com/photos/oneaustin/1261907803
TL;DR




        http://www.flickr.com/photos/evilaugust/3307382858
TL;DR

  Mobile Apps need an API

  Ruby on Rails is good for writing APIs

  You can build nice admin interfaces
with ActiveAdmin

  You can craft Javascript Apps easily
using the asset pipeline.
RubyDay.it
15 June 2012

   www.rubyday.it
Any Questions?
Thank You!

More Related Content

What's hot (20)

PPTX
REST API Best Practices & Implementing in Codeigniter
Sachin G Kulkarni
 
ODP
Consume RESTful APIs with $resource and Restangular
John Schmidt
 
PDF
Finding Restfulness - Madrid.rb April 2014
samlown
 
PDF
Denver emberjs-sept-2015
Ron White
 
PDF
Rails 3: Dashing to the Finish
Yehuda Katz
 
PDF
Introduction to plugin development
Caldera Labs
 
PDF
"Managing API Complexity". Matthew Flaming, Temboo
Yandex
 
PPTX
RESTful API Design Best Practices Using ASP.NET Web API
💻 Spencer Schneidenbach
 
PPT
Mashups & APIs
Pamela Fox
 
PDF
Building Better Web APIs with Rails
All Things Open
 
PDF
Django REST Framework における API 実装プラクティス | PyCon JP 2018
Masashi Shibata
 
PDF
Building Beautiful REST APIs with ASP.NET Core
Stormpath
 
KEY
Simple Web Apps With Sinatra
a_l
 
PDF
Introduction à Ruby
Microsoft
 
KEY
SproutCore is Awesome - HTML5 Summer DevFest
tomdale
 
PDF
Crafting Quality PHP Applications (ConFoo YVR 2017)
James Titcumb
 
PDF
Rails 4.0
Robert Gogolok
 
PDF
Découplez votre appli en micro-APIs
Nicolas Blanco
 
PDF
Deliver Business Value Faster with AWS Step Functions
Daniel Zivkovic
 
PDF
Kicking off with Zend Expressive and Doctrine ORM (ConFoo YVR 2017)
James Titcumb
 
REST API Best Practices & Implementing in Codeigniter
Sachin G Kulkarni
 
Consume RESTful APIs with $resource and Restangular
John Schmidt
 
Finding Restfulness - Madrid.rb April 2014
samlown
 
Denver emberjs-sept-2015
Ron White
 
Rails 3: Dashing to the Finish
Yehuda Katz
 
Introduction to plugin development
Caldera Labs
 
"Managing API Complexity". Matthew Flaming, Temboo
Yandex
 
RESTful API Design Best Practices Using ASP.NET Web API
💻 Spencer Schneidenbach
 
Mashups & APIs
Pamela Fox
 
Building Better Web APIs with Rails
All Things Open
 
Django REST Framework における API 実装プラクティス | PyCon JP 2018
Masashi Shibata
 
Building Beautiful REST APIs with ASP.NET Core
Stormpath
 
Simple Web Apps With Sinatra
a_l
 
Introduction à Ruby
Microsoft
 
SproutCore is Awesome - HTML5 Summer DevFest
tomdale
 
Crafting Quality PHP Applications (ConFoo YVR 2017)
James Titcumb
 
Rails 4.0
Robert Gogolok
 
Découplez votre appli en micro-APIs
Nicolas Blanco
 
Deliver Business Value Faster with AWS Step Functions
Daniel Zivkovic
 
Kicking off with Zend Expressive and Doctrine ORM (ConFoo YVR 2017)
James Titcumb
 

Viewers also liked (18)

PDF
E così vuoi sviluppare un'app
Matteo Collina
 
PDF
Making things that works with us codemotion
Matteo Collina
 
PDF
Crea il TUO database con LevelDB e Node.js
Matteo Collina
 
PDF
E così vuoi sviluppare un'app (ci servono le APi!)
Matteo Collina
 
PDF
No. la sottile arte di trovare il tempo dove non esite.
Matteo Collina
 
PDF
CI-18n
Matteo Collina
 
PDF
Making things that works with us
Matteo Collina
 
PDF
The usability of open data
Matteo Collina
 
PDF
The internet of things - Rails Girls Galway
Matteo Collina
 
PDF
Making things that works with us - First Italian Internet of Things Day
Matteo Collina
 
PDF
Designing and developing mobile web applications with Mockup, Sencha Touch an...
Matteo Collina
 
PDF
Building a multi protocol broker for the internet of things using nodejs
Matteo Collina
 
PDF
No. la sottile arte di trovare il tempo dove non esite - codemotion 2015
Matteo Collina
 
PDF
L'universo dietro alle App
Matteo Collina
 
PDF
Operational transformation
Matteo Collina
 
PDF
Exposing M2M to the REST of us
Matteo Collina
 
PDF
Making things that work with us - Distill
Matteo Collina
 
PDF
Making your washing machine talk with a power plant
Matteo Collina
 
E così vuoi sviluppare un'app
Matteo Collina
 
Making things that works with us codemotion
Matteo Collina
 
Crea il TUO database con LevelDB e Node.js
Matteo Collina
 
E così vuoi sviluppare un'app (ci servono le APi!)
Matteo Collina
 
No. la sottile arte di trovare il tempo dove non esite.
Matteo Collina
 
Making things that works with us
Matteo Collina
 
The usability of open data
Matteo Collina
 
The internet of things - Rails Girls Galway
Matteo Collina
 
Making things that works with us - First Italian Internet of Things Day
Matteo Collina
 
Designing and developing mobile web applications with Mockup, Sencha Touch an...
Matteo Collina
 
Building a multi protocol broker for the internet of things using nodejs
Matteo Collina
 
No. la sottile arte di trovare il tempo dove non esite - codemotion 2015
Matteo Collina
 
L'universo dietro alle App
Matteo Collina
 
Operational transformation
Matteo Collina
 
Exposing M2M to the REST of us
Matteo Collina
 
Making things that work with us - Distill
Matteo Collina
 
Making your washing machine talk with a power plant
Matteo Collina
 
Ad

Similar to Enter the app era with ruby on rails (20)

PDF
JSON and the APInauts
Wynn Netherland
 
KEY
RESTful Api practices Rails 3
Anton Narusberg
 
PPTX
MIKE Stack Introduction - MongoDB, io.js, KendoUI, and Express
Charlie Key
 
PDF
JSON REST API for WordPress
Taylor Lovett
 
PPTX
KazooCon 2014 - Introduction to Kazoo APIs!
2600Hz
 
PPTX
The JSON REST API for WordPress
Taylor Lovett
 
PDF
FOXX - a Javascript application framework on top of ArangoDB
ArangoDB Database
 
PDF
Development in the could: How do we do it(Cloud computing. Microservices. Faas)
Preply.com
 
PPTX
Building RESTful APIs w/ Grape
Daniel Doubrovkine
 
PDF
JSON Fuzzing: New approach to old problems
titanlambda
 
PDF
Graph Analysis over JSON, Larus
Neo4j
 
PDF
APIdays Zurich 2019 - Specification Driven Development for REST APIS Alexande...
apidays
 
PDF
APIdays Helsinki 2019 - Specification-Driven Development of REST APIs with Al...
apidays
 
PDF
Specification-Driven Development of REST APIs by Alexander Zinchuk
OdessaJS Conf
 
PDF
Symfony + GraphQL
Alex Demchenko
 
PPTX
Graphql + Symfony | Александр Демченко | CODEiD
CODEiD PHP Community
 
PDF
[2019 south bay meetup] Building more contextual message with Block Kit
Tomomi Imura
 
PDF
【AWS Developers Meetup】RESTful APIをChaliceで紐解く
Amazon Web Services Japan
 
PDF
Diseño y Desarrollo de APIs
Raúl Neis
 
PPTX
Crafting Evolvable Api Responses
darrelmiller71
 
JSON and the APInauts
Wynn Netherland
 
RESTful Api practices Rails 3
Anton Narusberg
 
MIKE Stack Introduction - MongoDB, io.js, KendoUI, and Express
Charlie Key
 
JSON REST API for WordPress
Taylor Lovett
 
KazooCon 2014 - Introduction to Kazoo APIs!
2600Hz
 
The JSON REST API for WordPress
Taylor Lovett
 
FOXX - a Javascript application framework on top of ArangoDB
ArangoDB Database
 
Development in the could: How do we do it(Cloud computing. Microservices. Faas)
Preply.com
 
Building RESTful APIs w/ Grape
Daniel Doubrovkine
 
JSON Fuzzing: New approach to old problems
titanlambda
 
Graph Analysis over JSON, Larus
Neo4j
 
APIdays Zurich 2019 - Specification Driven Development for REST APIS Alexande...
apidays
 
APIdays Helsinki 2019 - Specification-Driven Development of REST APIs with Al...
apidays
 
Specification-Driven Development of REST APIs by Alexander Zinchuk
OdessaJS Conf
 
Symfony + GraphQL
Alex Demchenko
 
Graphql + Symfony | Александр Демченко | CODEiD
CODEiD PHP Community
 
[2019 south bay meetup] Building more contextual message with Block Kit
Tomomi Imura
 
【AWS Developers Meetup】RESTful APIをChaliceで紐解く
Amazon Web Services Japan
 
Diseño y Desarrollo de APIs
Raúl Neis
 
Crafting Evolvable Api Responses
darrelmiller71
 
Ad

Recently uploaded (20)

PDF
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
PDF
NewMind AI Journal - Weekly Chronicles - July'25 Week II
NewMind AI
 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
PDF
Meetup Kickoff & Welcome - Rohit Yadav, CSIUG Chairman
ShapeBlue
 
PDF
Building Resilience with Digital Twins : Lessons from Korea
SANGHEE SHIN
 
PPTX
Building and Operating a Private Cloud with CloudStack and LINBIT CloudStack ...
ShapeBlue
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
PDF
Français Patch Tuesday - Juillet
Ivanti
 
PDF
Women in Automation Presents: Reinventing Yourself — Bold Career Pivots That ...
DianaGray10
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PDF
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
PPTX
Darren Mills The Migration Modernization Balancing Act: Navigating Risks and...
AWS Chicago
 
PDF
Why Orbit Edge Tech is a Top Next JS Development Company in 2025
mahendraalaska08
 
PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
PDF
Wojciech Ciemski for Top Cyber News MAGAZINE. June 2025
Dr. Ludmila Morozova-Buss
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PDF
July Patch Tuesday
Ivanti
 
PPTX
Building a Production-Ready Barts Health Secure Data Environment Tooling, Acc...
Barts Health
 
PDF
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
NewMind AI Journal - Weekly Chronicles - July'25 Week II
NewMind AI
 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
Meetup Kickoff & Welcome - Rohit Yadav, CSIUG Chairman
ShapeBlue
 
Building Resilience with Digital Twins : Lessons from Korea
SANGHEE SHIN
 
Building and Operating a Private Cloud with CloudStack and LINBIT CloudStack ...
ShapeBlue
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
Français Patch Tuesday - Juillet
Ivanti
 
Women in Automation Presents: Reinventing Yourself — Bold Career Pivots That ...
DianaGray10
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
Darren Mills The Migration Modernization Balancing Act: Navigating Risks and...
AWS Chicago
 
Why Orbit Edge Tech is a Top Next JS Development Company in 2025
mahendraalaska08
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 
Wojciech Ciemski for Top Cyber News MAGAZINE. June 2025
Dr. Ludmila Morozova-Buss
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
July Patch Tuesday
Ivanti
 
Building a Production-Ready Barts Health Secure Data Environment Tooling, Acc...
Barts Health
 
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 

Enter the app era with ruby on rails

  • 1. Enter the App Era with Ruby on Rails @matteocollina
  • 2. RubyDay.it 15 June 2012 www.rubyday.it
  • 4. www.mavigex.com www.wemobi.it
  • 5. How is built an App? http://www.flickr.com/photos/dschulian/3173331821/
  • 6. Code Icons by Fasticon
  • 7. Code Run Icons by Fasticon
  • 8. Code Run Server Icons by Fasticon
  • 9. Code Run Server Icons by Fasticon
  • 10. Code Run Server Icons by Fasticon
  • 11. Code I need to serve Run Server my data to Web and Mobile Apps Icons by Fasticon
  • 12. We need an API
  • 13. We need an API Who has APIs?
  • 16. Who has APIs? And many many others..
  • 17. We will develop an API
  • 18. We need to be fast! http://www.flickr.com/photos/oneaustin/1261907803
  • 19. We have just twenty minutes http://www.flickr.com/photos/oneaustin/1261907803
  • 20. What do we want to build? http://www.flickr.com/photos/oberazzi/318947873/
  • 21. Another tool for nerds? http://www.flickr.com/photos/eyesontheroad/2260731457/
  • 22. Another Todo List? http://www.flickr.com/photos/eyesontheroad/2260731457/
  • 24. Enter MCDo. The First Todo List delivered as a REST API
  • 25. The First Todo List delivered as a REST API
  • 27. Signup API Feature: Signup API As a MCDO developer In order to develop apps I want to register new users Scenario: Succesful signup When I call "/users.json" in POST with: """ { "user": { "email": "[email protected]", "password": "abcde", "password_confirmation": "abcde" } } """ Then the JSON should be: """ { "id": 1, "email": "[email protected]" } """
  • 28. Signup API Scenario: signup fails with a wrong password_confirmation When I call "/users.json" in POST with: """ { "user": { "email": "[email protected]", "password": "abcde", "password_confirmation": "abcde1" } } """ Then the JSON should be: """ { "errors": { "password": ["doesn't match confirmation"] } } """
  • 29. How?
  • 31. How? Ruby on Rails Let’s see some code! Cucumber RSpec JSON-spec
  • 33. Login API Feature: Login API As a MCDO developer In order to develop apps I want to login with an existing user Background: Given there is the following user: | email | password | password_confirmation | | [email protected] | aa | aa | Scenario: Succesful login When I call "/session.json" in POST with: """ { "email": "[email protected]", "password": "aa" } """ Then the JSON should be: """ { "status": "authenticated" } """
  • 34. Login API Scenario: Failed login When I call "/session.json" in POST with: """ { "email": "[email protected]", "password": "bb" } """ Then the JSON should be: """ { "status": "not authenticated" } """
  • 35. Login API Scenario: Validating an active session Given I call "/session.json" in POST with: """ { "email": "[email protected]", "password": "aa" } """ When I call "/session.json" in GET Then the JSON should be: """ { "status": "authenticated" } """
  • 36. Login API Scenario: Validating an active session Given I call "/session.json" in POST with: """ { "email": "[email protected]", "password": "aa" } Let’s see some code! """ When I call "/session.json" in GET Then the JSON should be: """ { "status": "authenticated" } """
  • 38. Lists API Feature: Lists API As a MCDO developer In order to develop apps I want to manage a user's lists Background: Given I login succesfully with user "[email protected]" Scenario: Default lists When I call "/lists.json" in GET Then the JSON should be: """ { "lists": [{ "id": 1, "name": "Personal", "link": "http://www.example.com/lists/1", "items_link": "http://www.example.com/lists/1/items" }] } """
  • 39. Lists API Scenario: Creating a list When I call "/lists.json" in POST with: """ { "list": { "name": "foobar" } } """ Then the JSON should be: """ { "name": "foobar", "items_link": "http://www.example.com/lists/1/items" } """
  • 40. Lists API Scenario: Creating a list should add it to the index Given I call "/lists.json" in POST with: """ { "list": { "name": "foobar" } } """ When I call "/lists.json" in GET Then the JSON should be: """ { "lists": [{ "id": 2, "name": "foobar", "link": "http://www.example.com/lists/2", "items_link": "http://www.example.com/lists/2/items" }, { "id": 1, "name": "Personal", "link": "http://www.example.com/lists/1", "items_link": "http://www.example.com/lists/1/items" }] } """
  • 41. Lists API Scenario: Removing a list (and the index is empty) Given I call "/lists/1.json" in DELETE When I call "/lists.json" Then the JSON should be: """ { "lists": [] } """ Scenario: Updating a list's name When I call "/lists/1.json" in PUT with: """ { "list": { "name": "foobar" } } """ Then the JSON should be: """ { "name": "foobar", "items_link": "http://www.example.com/lists/1/items" } """
  • 42. Lists API Scenario: Removing a list (and the index is empty) Given I call "/lists/1.json" in DELETE When I call "/lists.json" Then the JSON should be: """ { "lists": [] } """ Let’s see some code! Scenario: Updating a list's name When I call "/lists/1.json" in PUT with: """ { "list": { "name": "foobar" } } """ Then the JSON should be: """ { "name": "foobar", "items_link": "http://www.example.com/lists/1/items" } """
  • 44. Items API Feature: Manage a list's items As a developer In order to manipulate the list's item I want to access them through APIs Background: Given I login succesfully with user "[email protected]" Scenario: Default items When I call "/lists/1/items.json" in GET Then the JSON should be: """ { "items": [{ "name": "Insert your items!", "position": 0 }], "list_link": "http://www.example.com/lists/1" } """
  • 45. Items API Scenario: Moving an element to the top Given I call "/lists/1/items.json" in POST with: ... And I call "/lists/1/items.json" in POST with: ... When I call "/lists/1/items/2/move.json" in PUT with: """ { "position": 0 } """ Then the JSON should be: """ { "items": [{ "name": "b", "position": 0 }, { "name": "Insert your items!", "position": 1 }, { "name": "c", "position": 2 }], "list_link": "http://www.example.com/lists/1" } """
  • 46. Items API Scenario: Moving an element to the top Given I call "/lists/1/items.json" in POST with: ... And I call "/lists/1/items.json" in POST with: ... When I call "/lists/1/items/2/move.json" in PUT with: """ { "position": 0 } Let’s see some code! """ Then the JSON should be: """ { "items": [{ "name": "b", "position": 0 }, { "name": "Insert your items!", "position": 1 }, { "name": "c", "position": 2 }], "list_link": "http://www.example.com/lists/1" } """
  • 47. Do we need an admin panel?
  • 48. Do we need an admin panel?
  • 49. Do we need an admin panel? Put in your Gemfile: gem 'activeadmin' gem 'meta_search', '>= 1.1.0.pre' Then run: $ bundle install $ rails g active_admin:install $ rails g active_admin:resource users $ rails g active_admin:resource lists $ rails g active_admin:resource items $ rake db:migrate
  • 50. Do we need an admin panel? Put in your Gemfile: Let’s see some code! gem 'activeadmin' gem 'meta_search', '>= 1.1.0.pre' Then run: $ bundle install $ rails g active_admin:install $ rails g active_admin:resource users $ rails g active_admin:resource lists $ rails g active_admin:resource items $ rake db:migrate
  • 51. Build a JS App!
  • 52. Build a JS App! Backbone.js: MVC in the browser Rails asset pipeline concatenate and minifies our JS automatically We can even write our app in CoffeeScript: it works out of the box.
  • 53. Build a JS App! Backbone.js: MVC in the browser to Rails asset pipeline concatenate the code.. again? and minifies our JS automatically We can even write our app in CoffeeScript: it works out of the box.
  • 55. We are late, the #codemotion crew are kicking me out http://www.flickr.com/photos/oneaustin/1261907803
  • 56. TL;DR http://www.flickr.com/photos/evilaugust/3307382858
  • 57. TL;DR Mobile Apps need an API Ruby on Rails is good for writing APIs You can build nice admin interfaces with ActiveAdmin You can craft Javascript Apps easily using the asset pipeline.
  • 58. RubyDay.it 15 June 2012 www.rubyday.it