SlideShare une entreprise Scribd logo
1  sur  106
I can haz HTTP
Consuming and producing HTTP APIs in the
Ruby ecosystem
sidu ponnappa
kaiwren
@ponnappa
niranjan paranjape
achamian
@niranjan_p
Engineering

http://github.com/c42
Open Source
   (gem install) wrest
(gem install) pox_paginate
Not about HTTP libs
     not per se...
More about...
REST
caching
serialisation & deserialisation
authentication
stuff like that...
Producer / Consumer
Producer
digression
RESTful?
Leonard Richardson
L0: Plain Old Xml
L1: Resources



L0: Plain Old Xml
L2: HTTP Verbs



    L1: Resources



L0: Plain Old Xml
L3: Hypermedia



       L2: HTTP Verbs



    L1: Resources



L0: Plain Old Xml
reasonable compliance?
L2 is achievable with minimal
        effort in Rails
getting back to the point
Don’t mix machine stuff with
        human stuff
APIs are for machines
mixing the two causes trouble
basically, doing this causes
           trouble
def index
  respond_to do |format|
                e




    format.html
    format.json { render :json => Project.all.to_json }
  end
end
because, people like usable
          apps
separate API controllers from
    website controllers
or beyond even that...
your app only exposes APIs

   your website is a separate application
that consumes these APIs; think NewTwitter
don’t design exclusively for
      ActiveResource
        it isn’t a standard
HTTP status codes
rails has nice defaults
  201 for creates
  401 for auth violations
  405 for L2 violations
  406 for Content-Type violations
  422 for invalid data
  500 for server faults
  200 for everything else
let rails help you
what they missed
404
409
assert on status codes
     gem install rspec-http

    response.should be_im_a_teapot
Authentication
OAuth 2 is nice
be an OAuth provider
  consistency makes life easier
https://
Caching
go beyond Rails’ local caches
the Cache-Control header is
        your friend
Versioning
successful APIs change
good versioning is critical
publish clear roadmaps and deprecate sensibly
Content Types
don’t tunnel
application/x-www-form-urlencoded
Accept headers
“http://localhost:3000/user.xml”
“http://localhost:3000/user.xml”
rails respects it
  you should use it
Important stuff that we’ve
       never done
Throttling
https://github.com/dambalah/api-throttling
             (thanks @godfoca)
Metering
Consumer
rails API vs. everything else
ActiveResource
60:40
the rest of the time you
     monkeypatch
 but that isn’t so easy, so be careful
ActiveResource works best
  inside a walled garden
          (IMHO)
Producer maturity
some APIs are weird
everyone’s standardizing on
           REST
     but it’s what they call REST
suffice to say, one size doesn’t
              fit all
 except for OAuth 2, which everyone’s adopting
building a clean domain model
       for the API is key
OAuth 2 is ridiculously easy to
      write a client for
                 #justSaying
 https://github.com/kaiwren/wrest/tree/master/
             examples/facebook_auth
authorisation on the other
hand still has no standard
     implementation
What should a good HTTP
   client do for you?
this one needs bullets
•   Verbs - should support GET, POST, PUT & DELETE.
•   If it supports PATCH & OPTIONS, epic.
•   Transparent deserialization of XML and JSON, with the option to easily add more
•   HTTP caching (RFC 2616)
•   Keep-alive connections (because negotiating SSL can get expensive)
•   Thread safety
•   Transparent compression/decompression using Accept-Encoding
•   A fluent, easy to use API
most importantly...
verbs
serialization
I rather like ActiveSupport
caching
 RFC 2616
thread safety
fluent api
is it easy to work with uris, because you’ll do a fair bit of
               that when building domains
is it easy to build a domain
       model using it?
logging/debugging
Shared stuff
serialization/deserialization
libxml
ActiveSupport::XmlMini.backend = 'Nokogiri'
Builder
Pure Ruby XML serializer. Pretty Fast.
     Just does String concats.
gotcha
no DOM for Builder
so no guarantee that you get valid XML
testing
this can be tricky
Conclusion
respect HTTP
respect REST constraints
spend less time messing with
         plumbing
focus on building a clean
     domain model
Photo credits
David Blackwell, Elephant in Room: http://www.flickr.com/photos/mobilestreetlife
Funny picture?




cat with mausambi hat
42


      Sidu Ponnappa               Niranjan Paranjape



http://twitter.com/ponnappa http://twitter.com/niranjan_p

https://github.com/kaiwren   https://github.com/achamian

Contenu connexe

Tendances

Ruby vs Node ShiningRay Shanghai
Ruby vs Node ShiningRay ShanghaiRuby vs Node ShiningRay Shanghai
Ruby vs Node ShiningRay ShanghaiJackson Tian
 
OWIN (Open Web Interface for .NET)
OWIN (Open Web Interface for .NET)OWIN (Open Web Interface for .NET)
OWIN (Open Web Interface for .NET)Folio3 Software
 
C# ASP.NET WEB API APPLICATION DEVELOPMENT
C# ASP.NET WEB API APPLICATION DEVELOPMENTC# ASP.NET WEB API APPLICATION DEVELOPMENT
C# ASP.NET WEB API APPLICATION DEVELOPMENTDr. Awase Khirni Syed
 
OWIN and Katana Project - Not Only IIS - NoIIS
OWIN and Katana Project - Not Only IIS - NoIISOWIN and Katana Project - Not Only IIS - NoIIS
OWIN and Katana Project - Not Only IIS - NoIISBilal Haidar
 
Nom Nom: Consuming REST APIs
Nom Nom: Consuming REST APIsNom Nom: Consuming REST APIs
Nom Nom: Consuming REST APIsTessa Mero
 
Building a REST Service in minutes with Spring Boot
Building a REST Service in minutes with Spring BootBuilding a REST Service in minutes with Spring Boot
Building a REST Service in minutes with Spring BootOmri Spector
 
PHP Laravel Framework'üne Dalış
PHP Laravel Framework'üne DalışPHP Laravel Framework'üne Dalış
PHP Laravel Framework'üne Dalışemirkarsiyakali
 
All the Laravel things: up and running to making $$
All the Laravel things: up and running to making $$All the Laravel things: up and running to making $$
All the Laravel things: up and running to making $$Joe Ferguson
 
How to extend (properly) and old Alfresco Share feature
How to extend (properly) and old Alfresco Share featureHow to extend (properly) and old Alfresco Share feature
How to extend (properly) and old Alfresco Share featureAngel Borroy López
 
ASP.NET Core MVC + Web API with Overview
ASP.NET Core MVC + Web API with OverviewASP.NET Core MVC + Web API with Overview
ASP.NET Core MVC + Web API with OverviewShahed Chowdhuri
 
Composer Lightning Talk
Composer Lightning TalkComposer Lightning Talk
Composer Lightning TalkEric Johnson
 
Debugging the Web with Fiddler
Debugging the Web with FiddlerDebugging the Web with Fiddler
Debugging the Web with FiddlerIdo Flatow
 
Symfony Live San Francisco 2017 - Symfony @ OpenSky
Symfony Live San Francisco 2017 - Symfony @ OpenSkySymfony Live San Francisco 2017 - Symfony @ OpenSky
Symfony Live San Francisco 2017 - Symfony @ OpenSkyPablo Godel
 
One does not simply "Upgrade to Rails 3"
One does not simply "Upgrade to Rails 3"One does not simply "Upgrade to Rails 3"
One does not simply "Upgrade to Rails 3"testflyjets
 

Tendances (20)

Ruby vs Node ShiningRay Shanghai
Ruby vs Node ShiningRay ShanghaiRuby vs Node ShiningRay Shanghai
Ruby vs Node ShiningRay Shanghai
 
Event Machine
Event MachineEvent Machine
Event Machine
 
OWIN (Open Web Interface for .NET)
OWIN (Open Web Interface for .NET)OWIN (Open Web Interface for .NET)
OWIN (Open Web Interface for .NET)
 
C# ASP.NET WEB API APPLICATION DEVELOPMENT
C# ASP.NET WEB API APPLICATION DEVELOPMENTC# ASP.NET WEB API APPLICATION DEVELOPMENT
C# ASP.NET WEB API APPLICATION DEVELOPMENT
 
OWIN and Katana Project - Not Only IIS - NoIIS
OWIN and Katana Project - Not Only IIS - NoIISOWIN and Katana Project - Not Only IIS - NoIIS
OWIN and Katana Project - Not Only IIS - NoIIS
 
Owin and katana
Owin and katanaOwin and katana
Owin and katana
 
Os Mcmahan
Os McmahanOs Mcmahan
Os Mcmahan
 
Nom Nom: Consuming REST APIs
Nom Nom: Consuming REST APIsNom Nom: Consuming REST APIs
Nom Nom: Consuming REST APIs
 
Building a REST Service in minutes with Spring Boot
Building a REST Service in minutes with Spring BootBuilding a REST Service in minutes with Spring Boot
Building a REST Service in minutes with Spring Boot
 
PHP Laravel Framework'üne Dalış
PHP Laravel Framework'üne DalışPHP Laravel Framework'üne Dalış
PHP Laravel Framework'üne Dalış
 
All the Laravel things: up and running to making $$
All the Laravel things: up and running to making $$All the Laravel things: up and running to making $$
All the Laravel things: up and running to making $$
 
How to extend (properly) and old Alfresco Share feature
How to extend (properly) and old Alfresco Share featureHow to extend (properly) and old Alfresco Share feature
How to extend (properly) and old Alfresco Share feature
 
ASP.NET Core MVC + Web API with Overview
ASP.NET Core MVC + Web API with OverviewASP.NET Core MVC + Web API with Overview
ASP.NET Core MVC + Web API with Overview
 
Mini-Training Owin Katana
Mini-Training Owin KatanaMini-Training Owin Katana
Mini-Training Owin Katana
 
Composer Lightning Talk
Composer Lightning TalkComposer Lightning Talk
Composer Lightning Talk
 
Debugging the Web with Fiddler
Debugging the Web with FiddlerDebugging the Web with Fiddler
Debugging the Web with Fiddler
 
A Day of REST
A Day of RESTA Day of REST
A Day of REST
 
Symfony Live San Francisco 2017 - Symfony @ OpenSky
Symfony Live San Francisco 2017 - Symfony @ OpenSkySymfony Live San Francisco 2017 - Symfony @ OpenSky
Symfony Live San Francisco 2017 - Symfony @ OpenSky
 
One does not simply "Upgrade to Rails 3"
One does not simply "Upgrade to Rails 3"One does not simply "Upgrade to Rails 3"
One does not simply "Upgrade to Rails 3"
 
ASP.NET: Present and future
ASP.NET: Present and futureASP.NET: Present and future
ASP.NET: Present and future
 

En vedette

Transforming the Design Process
Transforming the Design ProcessTransforming the Design Process
Transforming the Design ProcessMarco Ferruzca
 
World Tower Sculpture Proposal
World Tower Sculpture ProposalWorld Tower Sculpture Proposal
World Tower Sculpture ProposalBockit
 
Present Perfect: forms and uses
Present Perfect: forms and usesPresent Perfect: forms and uses
Present Perfect: forms and usesMaribel Gonzalez
 
Internetix 2009 Brian Final Version Jhb
Internetix 2009 Brian Final Version JhbInternetix 2009 Brian Final Version Jhb
Internetix 2009 Brian Final Version JhbBrian Pinnock
 
Portent Webinar: Next-Level Segmentation
Portent Webinar: Next-Level SegmentationPortent Webinar: Next-Level Segmentation
Portent Webinar: Next-Level SegmentationIan Lurie
 
Java Script
Java ScriptJava Script
Java ScriptLiu Xing
 
Saved (part 2)
Saved (part 2)Saved (part 2)
Saved (part 2)jzatko
 
Orbul Si Ziaristul
Orbul Si ZiaristulOrbul Si Ziaristul
Orbul Si ZiaristulAlexandru S
 
Social Media & Small Business : Taking your first steps in Social Media
Social Media & Small Business : Taking your first steps in Social MediaSocial Media & Small Business : Taking your first steps in Social Media
Social Media & Small Business : Taking your first steps in Social MediaShashi Bellamkonda
 
Trends In New Media Luncheon at Optsum 2010
Trends In New Media Luncheon at Optsum 2010Trends In New Media Luncheon at Optsum 2010
Trends In New Media Luncheon at Optsum 2010Shashi Bellamkonda
 
SEO blogging best practices
SEO blogging best practicesSEO blogging best practices
SEO blogging best practicesIan Lurie
 
2007 development of a who growth reference for school aged children and adole...
2007 development of a who growth reference for school aged children and adole...2007 development of a who growth reference for school aged children and adole...
2007 development of a who growth reference for school aged children and adole...Raul Rojas
 
This Transliterate Life
This Transliterate LifeThis Transliterate Life
This Transliterate LifeBobbi Newman
 
Experts On Credit Crisis
Experts On Credit CrisisExperts On Credit Crisis
Experts On Credit CrisisAvinash Singh
 
What IA, UX and SEO Can Learn from Each Other
What IA, UX and SEO Can Learn from Each OtherWhat IA, UX and SEO Can Learn from Each Other
What IA, UX and SEO Can Learn from Each OtherIan Lurie
 
The Universe Problem: Poll results, Facebook and the 2012 Presidential campaign
The Universe Problem: Poll results, Facebook and the 2012 Presidential campaignThe Universe Problem: Poll results, Facebook and the 2012 Presidential campaign
The Universe Problem: Poll results, Facebook and the 2012 Presidential campaignIan Lurie
 

En vedette (20)

Video Games and Reader's Advisory
Video Games and Reader's AdvisoryVideo Games and Reader's Advisory
Video Games and Reader's Advisory
 
Transforming the Design Process
Transforming the Design ProcessTransforming the Design Process
Transforming the Design Process
 
U L Budayakerja
U L  BudayakerjaU L  Budayakerja
U L Budayakerja
 
World Tower Sculpture Proposal
World Tower Sculpture ProposalWorld Tower Sculpture Proposal
World Tower Sculpture Proposal
 
Present Perfect: forms and uses
Present Perfect: forms and usesPresent Perfect: forms and uses
Present Perfect: forms and uses
 
Internetix 2009 Brian Final Version Jhb
Internetix 2009 Brian Final Version JhbInternetix 2009 Brian Final Version Jhb
Internetix 2009 Brian Final Version Jhb
 
Portent Webinar: Next-Level Segmentation
Portent Webinar: Next-Level SegmentationPortent Webinar: Next-Level Segmentation
Portent Webinar: Next-Level Segmentation
 
Luis Felipe Pacheco LLanes, Senior OCM
Luis Felipe Pacheco LLanes, Senior OCMLuis Felipe Pacheco LLanes, Senior OCM
Luis Felipe Pacheco LLanes, Senior OCM
 
Java Script
Java ScriptJava Script
Java Script
 
Saved (part 2)
Saved (part 2)Saved (part 2)
Saved (part 2)
 
Orbul Si Ziaristul
Orbul Si ZiaristulOrbul Si Ziaristul
Orbul Si Ziaristul
 
Social Media & Small Business : Taking your first steps in Social Media
Social Media & Small Business : Taking your first steps in Social MediaSocial Media & Small Business : Taking your first steps in Social Media
Social Media & Small Business : Taking your first steps in Social Media
 
Trends In New Media Luncheon at Optsum 2010
Trends In New Media Luncheon at Optsum 2010Trends In New Media Luncheon at Optsum 2010
Trends In New Media Luncheon at Optsum 2010
 
SEO blogging best practices
SEO blogging best practicesSEO blogging best practices
SEO blogging best practices
 
2007 development of a who growth reference for school aged children and adole...
2007 development of a who growth reference for school aged children and adole...2007 development of a who growth reference for school aged children and adole...
2007 development of a who growth reference for school aged children and adole...
 
This Transliterate Life
This Transliterate LifeThis Transliterate Life
This Transliterate Life
 
Rutina[1]
Rutina[1]Rutina[1]
Rutina[1]
 
Experts On Credit Crisis
Experts On Credit CrisisExperts On Credit Crisis
Experts On Credit Crisis
 
What IA, UX and SEO Can Learn from Each Other
What IA, UX and SEO Can Learn from Each OtherWhat IA, UX and SEO Can Learn from Each Other
What IA, UX and SEO Can Learn from Each Other
 
The Universe Problem: Poll results, Facebook and the 2012 Presidential campaign
The Universe Problem: Poll results, Facebook and the 2012 Presidential campaignThe Universe Problem: Poll results, Facebook and the 2012 Presidential campaign
The Universe Problem: Poll results, Facebook and the 2012 Presidential campaign
 

Similaire à I can haz HTTP - Consuming and producing HTTP APIs in the Ruby ecosystem

Rails services in the walled garden
Rails services in the walled gardenRails services in the walled garden
Rails services in the walled gardenSidu Ponnappa
 
Flickr Services
Flickr ServicesFlickr Services
Flickr Servicesroyans
 
Flickr Services
Flickr ServicesFlickr Services
Flickr Servicesroyans
 
REST in ( a mobile ) peace @ WHYMCA 05-21-2011
REST in ( a mobile ) peace @ WHYMCA 05-21-2011REST in ( a mobile ) peace @ WHYMCA 05-21-2011
REST in ( a mobile ) peace @ WHYMCA 05-21-2011Alessandro Nadalin
 
Where is my scalable api?
Where is my scalable api?Where is my scalable api?
Where is my scalable api?Altoros
 
What’s New in Rails 5.0?
What’s New in Rails 5.0?What’s New in Rails 5.0?
What’s New in Rails 5.0?Unboxed
 
PHP is the King, nodejs is the Prince and Lua is the fool
PHP is the King, nodejs is the Prince and Lua is the foolPHP is the King, nodejs is the Prince and Lua is the fool
PHP is the King, nodejs is the Prince and Lua is the foolAlessandro Cinelli (cirpo)
 
API workshop: Introduction to APIs (TC Camp)
API workshop: Introduction to APIs (TC Camp)API workshop: Introduction to APIs (TC Camp)
API workshop: Introduction to APIs (TC Camp)Tom Johnson
 
JHipster Conf 2018 : Connect your JHipster apps to the world of APIs with Ope...
JHipster Conf 2018 : Connect your JHipster apps to the world of APIs with Ope...JHipster Conf 2018 : Connect your JHipster apps to the world of APIs with Ope...
JHipster Conf 2018 : Connect your JHipster apps to the world of APIs with Ope...chbornet
 
Open API Architectural Choices Considerations
Open API Architectural Choices ConsiderationsOpen API Architectural Choices Considerations
Open API Architectural Choices ConsiderationsDominiek ter Heide
 
Matt Gauger - Lamp vs. the world - MKE PHP Users Group - December 14, 2010
Matt Gauger - Lamp vs. the world - MKE PHP Users Group - December 14, 2010 Matt Gauger - Lamp vs. the world - MKE PHP Users Group - December 14, 2010
Matt Gauger - Lamp vs. the world - MKE PHP Users Group - December 14, 2010 Matt Gauger
 
REST-API introduction for developers
REST-API introduction for developersREST-API introduction for developers
REST-API introduction for developersPatrick Savalle
 
Seattle StrongLoop Node.js Workshop
Seattle StrongLoop Node.js WorkshopSeattle StrongLoop Node.js Workshop
Seattle StrongLoop Node.js WorkshopJimmy Guerrero
 

Similaire à I can haz HTTP - Consuming and producing HTTP APIs in the Ruby ecosystem (20)

Rails services in the walled garden
Rails services in the walled gardenRails services in the walled garden
Rails services in the walled garden
 
Crafting APIs
Crafting APIsCrafting APIs
Crafting APIs
 
Flickr Services
Flickr ServicesFlickr Services
Flickr Services
 
Flickr Services
Flickr ServicesFlickr Services
Flickr Services
 
Function as a Service
Function as a ServiceFunction as a Service
Function as a Service
 
Web services - REST and SOAP
Web services - REST and SOAPWeb services - REST and SOAP
Web services - REST and SOAP
 
Kiwipycon command line
Kiwipycon command lineKiwipycon command line
Kiwipycon command line
 
REST in ( a mobile ) peace @ WHYMCA 05-21-2011
REST in ( a mobile ) peace @ WHYMCA 05-21-2011REST in ( a mobile ) peace @ WHYMCA 05-21-2011
REST in ( a mobile ) peace @ WHYMCA 05-21-2011
 
Web Dev 21-01-2024.pptx
Web Dev 21-01-2024.pptxWeb Dev 21-01-2024.pptx
Web Dev 21-01-2024.pptx
 
Where is my scalable api?
Where is my scalable api?Where is my scalable api?
Where is my scalable api?
 
What’s New in Rails 5.0?
What’s New in Rails 5.0?What’s New in Rails 5.0?
What’s New in Rails 5.0?
 
Where is my scalable API?
Where is my scalable API?Where is my scalable API?
Where is my scalable API?
 
PHP is the King, nodejs is the Prince and Lua is the fool
PHP is the King, nodejs is the Prince and Lua is the foolPHP is the King, nodejs is the Prince and Lua is the fool
PHP is the King, nodejs is the Prince and Lua is the fool
 
Lamp
LampLamp
Lamp
 
API workshop: Introduction to APIs (TC Camp)
API workshop: Introduction to APIs (TC Camp)API workshop: Introduction to APIs (TC Camp)
API workshop: Introduction to APIs (TC Camp)
 
JHipster Conf 2018 : Connect your JHipster apps to the world of APIs with Ope...
JHipster Conf 2018 : Connect your JHipster apps to the world of APIs with Ope...JHipster Conf 2018 : Connect your JHipster apps to the world of APIs with Ope...
JHipster Conf 2018 : Connect your JHipster apps to the world of APIs with Ope...
 
Open API Architectural Choices Considerations
Open API Architectural Choices ConsiderationsOpen API Architectural Choices Considerations
Open API Architectural Choices Considerations
 
Matt Gauger - Lamp vs. the world - MKE PHP Users Group - December 14, 2010
Matt Gauger - Lamp vs. the world - MKE PHP Users Group - December 14, 2010 Matt Gauger - Lamp vs. the world - MKE PHP Users Group - December 14, 2010
Matt Gauger - Lamp vs. the world - MKE PHP Users Group - December 14, 2010
 
REST-API introduction for developers
REST-API introduction for developersREST-API introduction for developers
REST-API introduction for developers
 
Seattle StrongLoop Node.js Workshop
Seattle StrongLoop Node.js WorkshopSeattle StrongLoop Node.js Workshop
Seattle StrongLoop Node.js Workshop
 

Dernier

Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 

Dernier (20)

Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 

I can haz HTTP - Consuming and producing HTTP APIs in the Ruby ecosystem

Notes de l'éditeur

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. Opensource we have done in this area\n
  10. This talk is not about NetHTTP vs libcurl\n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. This talk does have *some* structure; we’ll look at APIs from the perspective of the producer and the consumer. With a little bit left over for stuff that bridges the gap.\n
  18. \n
  19. Everyone talks about how easy it is to produce APIs with Sinatra and such like, but lets be honest. There’s an elephant in the room - those of you that freelance know exactly how many requests we get for APIs on Sinatra versus APIs on...\n
  20. [Handoff]\n\n...Rails. Love it or hate it, Rails has a standard way of producing APIs, and understanding what Rails can or cannot do for you is important. Sinatra does not have these constraints, so you’re free to roll APIs any way you want, so we’ll focus on the framework that does impose significant patterns.\n
  21. [achamian]\n\nBut before we launch into Rails’ capabilities, it’s important to put things into context first by talking a little about REST\n
  22. What is a RESTful API?\n
  23. For this we turn to Leonard Richardson who came up with a maturity model that has gotten so famous it has an acronym and looks like...\n
  24. ...this, popularly known as the Richardson Maturity Model, or RMM. \nIt begins with Level 0, which uses plain old xml (or a similar encoding format) to tunnel requests to a HTTP endpoint. Think RPC. Clearly Rails is better than this.\nNext comes Level 1, which introduces the concept of Resources - every URI represents a resource. Easy peasy. Rails makes it easy to do this - but you’re free to deviate.\nThen comes Level 2, which defines a certain set of constraints around how HTTP verbs are used. Rails violates the semantics by using PUT instead of PATCH - this was fixed on May 07 with Pull request #348, so future releases should be L2 compliant.\nFinally, we come to L3 which involves using hypermedia to define the edges of the state graph of an application using hypermedia links. This definitely isn’t in Rails. Yet.\n
  25. ...this, popularly known as the Richardson Maturity Model, or RMM. \nIt begins with Level 0, which uses plain old xml (or a similar encoding format) to tunnel requests to a HTTP endpoint. Think RPC. Clearly Rails is better than this.\nNext comes Level 1, which introduces the concept of Resources - every URI represents a resource. Easy peasy. Rails makes it easy to do this - but you’re free to deviate.\nThen comes Level 2, which defines a certain set of constraints around how HTTP verbs are used. Rails violates the semantics by using PUT instead of PATCH - this was fixed on May 07 with Pull request #348, so future releases should be L2 compliant.\nFinally, we come to L3 which involves using hypermedia to define the edges of the state graph of an application using hypermedia links. This definitely isn’t in Rails. Yet.\n
  26. ...this, popularly known as the Richardson Maturity Model, or RMM. \nIt begins with Level 0, which uses plain old xml (or a similar encoding format) to tunnel requests to a HTTP endpoint. Think RPC. Clearly Rails is better than this.\nNext comes Level 1, which introduces the concept of Resources - every URI represents a resource. Easy peasy. Rails makes it easy to do this - but you’re free to deviate.\nThen comes Level 2, which defines a certain set of constraints around how HTTP verbs are used. Rails violates the semantics by using PUT instead of PATCH - this was fixed on May 07 with Pull request #348, so future releases should be L2 compliant.\nFinally, we come to L3 which involves using hypermedia to define the edges of the state graph of an application using hypermedia links. This definitely isn’t in Rails. Yet.\n
  27. So what level of compliance can we achieve with a minimum of effort?\n
  28. [Handoff]\n\nI’d say an L2 is quite easily do-able in rails without too much effort. Now lets talk about how.\n
  29. [kaiwren]\n\nSo after that little digression, lets go back to what we were originally talking about - how to build APIs on Rails.\n
  30. [kaiwren]\n\nThis is one of the easiest thing to forget - APIs are for machines and software, websites are for people. Mixing the two is Not Good.\n
  31. \n
  32. \n
  33. Hollywood has shown us the consequence of mixing people stuff with machine stuff time and again, and it isn’t good.\n
  34. \n
  35. \n
  36. \n
  37. and REST cares only about state transitions. If you mix these, then remember that this only works in the most trivial of use cases. Beyond that...\n
  38. \n
  39. \n
  40. Your app doesn’t have a single HTML page. This is especially useful if you expect 3rd parties to use your APIs - you’re dogfooding your own stuff from day one.\n
  41. [Handoff]\n\nif your api is being consumed by 3rd parties, be aware that they will use a fairly eclectic collection of HTTP libs. What’s convenient/intuitive when using AR may be extremely obscure when using simple HTTP calls.\n
  42. [achamian]\n\nThe next thing everybody should keep an eye on when building Rails APIs are the HTTP status codes. There are many of them, and your APIs should respect them.\n
  43. The first thing everybody ignores when building Rails APIs are the HTTP status codes. There are many of them, and your APIs should respect them.\n
  44. Adhere to these defaults in the code you write. They’re there for a reason. Don’t, for example, return a 200 with an error message in the body - that’s bad form.\n
  45. There are, however, a couple of codes they deal with weirdly, or not at all\n
  46. The handling of 404s can be strange, driven as it is in certain cases by the ActiveRecord::RecordNotFound exception. Make sure that if a resource is not found, you’re always returning a 404 status code and you write a spec to expect it.\n
  47. Have a unique constraint on a resource identifier which is part of the input and not system assigned? When it’s violated, return a 409-Conflict and not a 422-Unprocessable entity.\n
  48. It’s important to lock these codes in because they mean a lot to the outside world. When building apis, make sure all your controller specs include assertions on the response code. I’ve got a simple gem that can help if you use rspec. Try it out. That asserts that a response has a code of 418.\n
  49. \n
  50. \n
  51. This way your application doesn’t need to deal with your own users through one auth mechanism and those that come through fb/twitter/github/sf through another\n
  52. Oauth 2 requires SSL, so do keep that in mind.\n
  53. \n
  54. \n
  55. If you have resources that don’t need to be refreshed as soon as they change, you should use an appropriate expires header to allow intermediate nodes on the network to cache them for a specified period of time. This can massively reduce load on your servers.\n
  56. \n
  57. \n
  58. Just like any library or gem, your users require visibility and stability. Whether you use URL based versioning (by including v1/v2/v3) in the API url, or by headers that specify the version, make sure your versioning roadmap is clear, consistent and sensible. Try maintaining backward compatibility as far as is reasonable.\n
  59. Content Types are rarely done wrong, so I won’t talk about them for too long. There’s only one thing that I’ve observed out here...\n
  60. ... is folks tunneling application/x-www-form-urlencoded over application/xml or application/json.\n
  61. \n
  62. \n
  63. a suffix of .xml or .json in the URI is to make it easier to look at api responses in the browser. While consuming an API you should stick to the Accept header.\n
  64. There are a couple of important things when dealing with APIs that I’ve never done and have no first-hand experience with\n
  65. Solved using rack middleware\n
  66. [Handoff]\n
  67. [kaiwren]\n
  68. Are you talking to a rails app (typically within your own walled garden) or to an API out on the internets?\n
  69. Let’s talk about the consumer that ships with Rails - ActiveResource\n
  70. ActiveResource follows the 60/40 rule not 80/20 - it works for the straightforward use cases, and does so smoothly and well\n
  71. Trying accessing the header information for a response\n
  72. \n
  73. \n
  74. Passing parameters for a post request. Accepting access token as a parameter to a Get over https \n
  75. \n
  76. \n
  77. \n
  78. You don’t need gems for OAuth2 clients. Just roll your own - it takes 20 minutes tops.\n
  79. \n
  80. \n
  81. \n
  82. \n
  83. \n
  84. \n
  85. \n
  86. \n
  87. \n
  88. \n
  89. Can I figure out the verb, the connection (if keep alive), corelate the req and response a situation where parallel threads are logging to the same log\n
  90. These are the bits that both producers and consumers deal with\n
  91. A significant proportion of the time an API takes to process something is spent doing serialisation and deserialization\n
  92. Remember to switch your deserialization backend from REXML to Nokogiri which uses the native libxml library. It’s way way faster.\n
  93. The default XML serializer in Rails is written in pure Ruby. It’s pretty fast, and there are drop in native alternatives based off libxml that are upto 50% faster, but that aren’t particularly popular.\n
  94. The big gotcha with builder occurs when you’re generating custom XML\n
  95. you want to run all the custom xml you create using builder’s DSLs through Nokogiri’s deserialise to make sure its valid XML in your specs\n
  96. In addition to controller specs, it makes sense to have full, live tests hitting a real server, especially if you’re integrating across multiple APIs that you’ve authored\n
  97. \n
  98. \n
  99. \n
  100. \n
  101. \n
  102. \n
  103. \n
  104. \n