SlideShare a Scribd company logo
1 of 14
Download to read offline
créer son API
              Raphaël Audet
              Pierre Renaudin
              Apéro Ruby Bordeaux, 10 Janvier 2011



mardi 10 janvier 12
créer son API

        • Pourquoi créer son API ?
        • Quelles sont les solutions qui existent ?
        • Démo d’une API réalisée avec RABL




mardi 10 janvier 12
Pourquoi une API ? 1/2
             • Pour ouvrir son application à des acteurs
                      externes

                                 api.twitter.com




    site de recherche
                                        blog       app facebook
        sur twitter


mardi 10 janvier 12
Pourquoi une API ? 2/2
             • Pour séparer les clients ( web, mobile ...) du
                      serveur et améliorer les performances

                                   api.twitter.com




               client web             client mobile      client iphone


mardi 10 janvier 12
Solution 1 : utiliser rails
    class User < ActiveRecord::Base

       field :first_name       Texte
       field :last_name
       field :address

      def name
       self.first_name + ' ' + self.last_name
                                                  {
      end
    end
                                                      id: ‘28ds84dsd’,
                      models/users.rb                 first_name: ‘Ted’,
                                                      last_name: ‘Penn’,
  class UsersController < ApplicationController
                                                      address: ‘3 rue Anchor...’
      def show                                        }
       render :json => @user
      end

  end




controllers/users_controller.rb
mardi 10 janvier 12
Solution 2 : utiliser acts_as_api
    class User < ActiveRecord::Base

       acts_as_api

       api_accessible :public do |t|
        t.add :id
        t.add :name
       end

      def name                                    {
       self.first_name + ' ' + self.last_name
      end                                             id: ‘28ds84dsd’,
    end
                                                      name: ‘Ted Penn’
                      models/users.rb                 }
  class UsersController < ApplicationController

      def show
       render_for_api :public, :json => @user
      end

  end


controllers/users_controller.rb
mardi 10 janvier 12
Solution 3 : utiliser RABL

  class UsersController < ApplicationController

      def show
       render @user
      end                                         {
  end
                                                      id: ‘28ds84dsd’,
                                                      name: ‘Ted Penn’,
controllers/users_controller.rb
                                                      pets: [
                                                       {name: ‘choupette’},
  attributes :id, :name
                                                       {name: ‘choupy’}
  child :pets do                                      ]}
    extends ‘pets/base’
  end




     views/users/show.json.rabl
mardi 10 janvier 12
Démo - 1




mardi 10 janvier 12
Démo - 2




mardi 10 janvier 12
Démo - 3




                      controllers/messages_controller.rb




mardi 10 janvier 12
Démo : RABL WAY ! 4


                      Gemfile




  views/messages/index.rabl    messages_controller.rb


mardi 10 janvier 12
Démo - 5




mardi 10 janvier 12
Démo : autre exemple 6




                      views/users/base.json.rabl




mardi 10 janvier 12
Références
  •Rabl : https://github.com/nesquena/rabl
  •acts_as_api : https://github.com/fabrik42/acts_as_api




mardi 10 janvier 12

More Related Content

Featured

AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 

Featured (20)

AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 

Apéro ruby bordeaux créer son api avec ruby - 9 01 2012

  • 1. créer son API Raphaël Audet Pierre Renaudin Apéro Ruby Bordeaux, 10 Janvier 2011 mardi 10 janvier 12
  • 2. créer son API • Pourquoi créer son API ? • Quelles sont les solutions qui existent ? • Démo d’une API réalisée avec RABL mardi 10 janvier 12
  • 3. Pourquoi une API ? 1/2 • Pour ouvrir son application à des acteurs externes api.twitter.com site de recherche blog app facebook sur twitter mardi 10 janvier 12
  • 4. Pourquoi une API ? 2/2 • Pour séparer les clients ( web, mobile ...) du serveur et améliorer les performances api.twitter.com client web client mobile client iphone mardi 10 janvier 12
  • 5. Solution 1 : utiliser rails class User < ActiveRecord::Base field :first_name Texte field :last_name field :address def name self.first_name + ' ' + self.last_name { end end id: ‘28ds84dsd’, models/users.rb first_name: ‘Ted’, last_name: ‘Penn’, class UsersController < ApplicationController address: ‘3 rue Anchor...’ def show } render :json => @user end end controllers/users_controller.rb mardi 10 janvier 12
  • 6. Solution 2 : utiliser acts_as_api class User < ActiveRecord::Base acts_as_api api_accessible :public do |t| t.add :id t.add :name end def name { self.first_name + ' ' + self.last_name end id: ‘28ds84dsd’, end name: ‘Ted Penn’ models/users.rb } class UsersController < ApplicationController def show render_for_api :public, :json => @user end end controllers/users_controller.rb mardi 10 janvier 12
  • 7. Solution 3 : utiliser RABL class UsersController < ApplicationController def show render @user end { end id: ‘28ds84dsd’, name: ‘Ted Penn’, controllers/users_controller.rb pets: [ {name: ‘choupette’}, attributes :id, :name {name: ‘choupy’} child :pets do ]} extends ‘pets/base’ end views/users/show.json.rabl mardi 10 janvier 12
  • 8. Démo - 1 mardi 10 janvier 12
  • 9. Démo - 2 mardi 10 janvier 12
  • 10. Démo - 3 controllers/messages_controller.rb mardi 10 janvier 12
  • 11. Démo : RABL WAY ! 4 Gemfile views/messages/index.rabl messages_controller.rb mardi 10 janvier 12
  • 12. Démo - 5 mardi 10 janvier 12
  • 13. Démo : autre exemple 6 views/users/base.json.rabl mardi 10 janvier 12
  • 14. Références •Rabl : https://github.com/nesquena/rabl •acts_as_api : https://github.com/fabrik42/acts_as_api mardi 10 janvier 12