SlideShare ist ein Scribd-Unternehmen logo
1 von 10
RESTful API practices
One Backend
          Multiple Clients
   Web Front-end                      Mobile
    (backbone.js,                  (Android, iOS,
javascriptmvc.js etc.)              BlackBerry,
                                  Symbian, WP7?)

                   Third party
                   applications
API planning
•   RESTful - no-brainer for Rails people

•   Minimum viable API - Released features must be
    maintained and probably supported in next versions

•   Versioning - URI design

•   Formats - Json ... (xml?)

•   Authentication
Versioning
From the client side

  •   URI design

      •   www.myapp.com/api/v1

      •   api.myapp.com/v1



  •   Custom header X-SMTH-Api-ver: 1
Versioning
From the back-end

 •   Sub-controllers

     •   app/controllers/api/v1/

     •   app/controllers/api/v2/

 •   Routes

 •   Models - mixins
Request and response
      formats
  respond_with method in Rails 3
Authentication

•   Session based - Devise



•   Request based - client provides his ID and a
    signature
Testing
                                                                                       describe "post create" do
Create Post
                                                                                         describe "when post is valid" do
[POST] /api/v1/post.json
                                                                                           it "should respond with created"
[PROPERTIES]
                                                                                           it "should respond with created post"
       • post: this object specifies the data to be created as a post (required)
                • third_party_id (required)                                                it "should have only allowed attributes in response object"
                • content (required)
                                                                                         end
[EXAMPLE REQUEST]
                                                                                         describe "when post is invalid" do
POST http://cannedapps.com:3838/api/post.json
                                                                                           
    "post": {                                                                              it "should respond with unprocessable entity"
      "third_party_id": 142,
      "content": "Hi Guys!"                                                              end
    }
                                                                                       end
On Success:
Http status code 201 is returned, with a response body including the created
participant id.

[EXAMPLE RESPONSE]

{
    "id": 767,
    "third_party_id": 142,
    "content": "Hi Guys!",
    "updated_at": "2011-04-14 07:18:43"
}

If a create or update action failed, HTTP status code 422 Unprocessable Entity
and a JSON-encoded body of localized error messages will be returned.
Example
https://github.com/naru/API-practices-demo
Thank you!
  Anton Narusberg

     Cannedapps

    github.com/naru
anton@cannedapps.com
   @antonnarusberg

Weitere ähnliche Inhalte

Was ist angesagt?

Building APIs in an easy way using API Platform
Building APIs in an easy way using API PlatformBuilding APIs in an easy way using API Platform
Building APIs in an easy way using API PlatformAntonio Peric-Mazar
 
Put a Button on It: Removing Barriers to Going Fast
Put a Button on It: Removing Barriers to Going FastPut a Button on It: Removing Barriers to Going Fast
Put a Button on It: Removing Barriers to Going FastOSCON Byrum
 
Project Fedena and Why Ruby on Rails - ArvindArvind G S
Project Fedena and Why Ruby on Rails - ArvindArvind G SProject Fedena and Why Ruby on Rails - ArvindArvind G S
Project Fedena and Why Ruby on Rails - ArvindArvind G SThoughtWorks
 
Modern websites in 2020 and Joomla
Modern websites in 2020 and JoomlaModern websites in 2020 and Joomla
Modern websites in 2020 and JoomlaGeorge Wilson
 
JSON REST API for WordPress
JSON REST API for WordPressJSON REST API for WordPress
JSON REST API for WordPressTaylor Lovett
 
An Intense Overview of the React Ecosystem
An Intense Overview of the React EcosystemAn Intense Overview of the React Ecosystem
An Intense Overview of the React EcosystemRami Sayar
 
Intro to Ruby on Rails
Intro to Ruby on RailsIntro to Ruby on Rails
Intro to Ruby on RailsMark Menard
 
Melbourne User Group OAK and MongoDB
Melbourne User Group OAK and MongoDBMelbourne User Group OAK and MongoDB
Melbourne User Group OAK and MongoDBYuval Ararat
 
Apache Cayenne: a Java ORM Alternative
Apache Cayenne: a Java ORM AlternativeApache Cayenne: a Java ORM Alternative
Apache Cayenne: a Java ORM AlternativeAndrus Adamchik
 
Riding rails for 10 years
Riding rails for 10 yearsRiding rails for 10 years
Riding rails for 10 yearsjduff
 
API Development with Laravel
API Development with LaravelAPI Development with Laravel
API Development with LaravelMichael Peacock
 
Ruby w/o Rails (Олександр Сімонов)
Ruby w/o Rails (Олександр Сімонов)Ruby w/o Rails (Олександр Сімонов)
Ruby w/o Rails (Олександр Сімонов)Fwdays
 
CIRCUIT 2015 - AEM Infrastructure Automation with Chef Cookbooks
CIRCUIT 2015 - AEM Infrastructure Automation with Chef CookbooksCIRCUIT 2015 - AEM Infrastructure Automation with Chef Cookbooks
CIRCUIT 2015 - AEM Infrastructure Automation with Chef CookbooksICF CIRCUIT
 
How Shopify Scales Rails
How Shopify Scales RailsHow Shopify Scales Rails
How Shopify Scales Railsjduff
 
Hybrid Mobile Development with Apache Cordova and
Hybrid Mobile Development with Apache Cordova and Hybrid Mobile Development with Apache Cordova and
Hybrid Mobile Development with Apache Cordova and Ryan Cuprak
 
Rails as iOS Application Backend
Rails as iOS Application BackendRails as iOS Application Backend
Rails as iOS Application Backendmaximeguilbot
 
django Forms in a Web API World
django Forms in a Web API Worlddjango Forms in a Web API World
django Forms in a Web API WorldTareque Hossain
 
From Ruby on Rails to RubyMotion - Writing your First iOS App with RubyMotion
From Ruby on Rails to RubyMotion - Writing your First iOS App with RubyMotionFrom Ruby on Rails to RubyMotion - Writing your First iOS App with RubyMotion
From Ruby on Rails to RubyMotion - Writing your First iOS App with RubyMotionMichael Denomy
 
Rails and iOS with RestKit
Rails and iOS with RestKitRails and iOS with RestKit
Rails and iOS with RestKitAndrew Culver
 

Was ist angesagt? (20)

Building APIs in an easy way using API Platform
Building APIs in an easy way using API PlatformBuilding APIs in an easy way using API Platform
Building APIs in an easy way using API Platform
 
Put a Button on It: Removing Barriers to Going Fast
Put a Button on It: Removing Barriers to Going FastPut a Button on It: Removing Barriers to Going Fast
Put a Button on It: Removing Barriers to Going Fast
 
Project Fedena and Why Ruby on Rails - ArvindArvind G S
Project Fedena and Why Ruby on Rails - ArvindArvind G SProject Fedena and Why Ruby on Rails - ArvindArvind G S
Project Fedena and Why Ruby on Rails - ArvindArvind G S
 
Modern websites in 2020 and Joomla
Modern websites in 2020 and JoomlaModern websites in 2020 and Joomla
Modern websites in 2020 and Joomla
 
JSON REST API for WordPress
JSON REST API for WordPressJSON REST API for WordPress
JSON REST API for WordPress
 
WCM-7 Surfing with CMIS
WCM-7 Surfing with CMISWCM-7 Surfing with CMIS
WCM-7 Surfing with CMIS
 
An Intense Overview of the React Ecosystem
An Intense Overview of the React EcosystemAn Intense Overview of the React Ecosystem
An Intense Overview of the React Ecosystem
 
Intro to Ruby on Rails
Intro to Ruby on RailsIntro to Ruby on Rails
Intro to Ruby on Rails
 
Melbourne User Group OAK and MongoDB
Melbourne User Group OAK and MongoDBMelbourne User Group OAK and MongoDB
Melbourne User Group OAK and MongoDB
 
Apache Cayenne: a Java ORM Alternative
Apache Cayenne: a Java ORM AlternativeApache Cayenne: a Java ORM Alternative
Apache Cayenne: a Java ORM Alternative
 
Riding rails for 10 years
Riding rails for 10 yearsRiding rails for 10 years
Riding rails for 10 years
 
API Development with Laravel
API Development with LaravelAPI Development with Laravel
API Development with Laravel
 
Ruby w/o Rails (Олександр Сімонов)
Ruby w/o Rails (Олександр Сімонов)Ruby w/o Rails (Олександр Сімонов)
Ruby w/o Rails (Олександр Сімонов)
 
CIRCUIT 2015 - AEM Infrastructure Automation with Chef Cookbooks
CIRCUIT 2015 - AEM Infrastructure Automation with Chef CookbooksCIRCUIT 2015 - AEM Infrastructure Automation with Chef Cookbooks
CIRCUIT 2015 - AEM Infrastructure Automation with Chef Cookbooks
 
How Shopify Scales Rails
How Shopify Scales RailsHow Shopify Scales Rails
How Shopify Scales Rails
 
Hybrid Mobile Development with Apache Cordova and
Hybrid Mobile Development with Apache Cordova and Hybrid Mobile Development with Apache Cordova and
Hybrid Mobile Development with Apache Cordova and
 
Rails as iOS Application Backend
Rails as iOS Application BackendRails as iOS Application Backend
Rails as iOS Application Backend
 
django Forms in a Web API World
django Forms in a Web API Worlddjango Forms in a Web API World
django Forms in a Web API World
 
From Ruby on Rails to RubyMotion - Writing your First iOS App with RubyMotion
From Ruby on Rails to RubyMotion - Writing your First iOS App with RubyMotionFrom Ruby on Rails to RubyMotion - Writing your First iOS App with RubyMotion
From Ruby on Rails to RubyMotion - Writing your First iOS App with RubyMotion
 
Rails and iOS with RestKit
Rails and iOS with RestKitRails and iOS with RestKit
Rails and iOS with RestKit
 

Andere mochten auch

Android app development basics
Android app development basicsAndroid app development basics
Android app development basicsAnton Narusberg
 
Android application development the basics (2)
Android application development the basics (2)Android application development the basics (2)
Android application development the basics (2)Aliyu Olalekan
 
Android development basics
Android development basicsAndroid development basics
Android development basicsPramesh Gautam
 
Android development - the basics, MFF UK, 2014
Android development - the basics, MFF UK, 2014Android development - the basics, MFF UK, 2014
Android development - the basics, MFF UK, 2014Tomáš Kypta
 

Andere mochten auch (6)

Ruby singleton class
Ruby singleton classRuby singleton class
Ruby singleton class
 
WebGL and three.js
WebGL and three.jsWebGL and three.js
WebGL and three.js
 
Android app development basics
Android app development basicsAndroid app development basics
Android app development basics
 
Android application development the basics (2)
Android application development the basics (2)Android application development the basics (2)
Android application development the basics (2)
 
Android development basics
Android development basicsAndroid development basics
Android development basics
 
Android development - the basics, MFF UK, 2014
Android development - the basics, MFF UK, 2014Android development - the basics, MFF UK, 2014
Android development - the basics, MFF UK, 2014
 

Ähnlich wie RESTful Api practices Rails 3

Enter the app era with ruby on rails (rubyday)
Enter the app era with ruby on rails (rubyday)Enter the app era with ruby on rails (rubyday)
Enter the app era with ruby on rails (rubyday)Matteo Collina
 
Enter the app era with ruby on rails
Enter the app era with ruby on railsEnter the app era with ruby on rails
Enter the app era with ruby on railsMatteo Collina
 
Building RESTful APIs w/ Grape
Building RESTful APIs w/ GrapeBuilding RESTful APIs w/ Grape
Building RESTful APIs w/ GrapeDaniel Doubrovkine
 
Building APIs in an easy way using API Platform
Building APIs in an easy way using API PlatformBuilding APIs in an easy way using API Platform
Building APIs in an easy way using API PlatformAntonio Peric-Mazar
 
Graphql + Symfony | Александр Демченко | CODEiD
Graphql + Symfony | Александр Демченко | CODEiDGraphql + Symfony | Александр Демченко | CODEiD
Graphql + Symfony | Александр Демченко | CODEiDCODEiD PHP Community
 
JSON REST API for WordPress
JSON REST API for WordPressJSON REST API for WordPress
JSON REST API for WordPressTaylor Lovett
 
iOS Swift application architecture
iOS Swift application architectureiOS Swift application architecture
iOS Swift application architectureRomain Rochegude
 
Building Better Web APIs with Rails
Building Better Web APIs with RailsBuilding Better Web APIs with Rails
Building Better Web APIs with RailsAll Things Open
 
From System Engineer to Gopher
From System Engineer to GopherFrom System Engineer to Gopher
From System Engineer to GopherI-Fan Wang
 
AtlasCamp2014: Introducing the Confluence REST API
AtlasCamp2014: Introducing the Confluence REST APIAtlasCamp2014: Introducing the Confluence REST API
AtlasCamp2014: Introducing the Confluence REST APIAtlassian
 
[2019 south bay meetup] Building more contextual message with Block Kit
[2019 south bay meetup] Building more contextual message with Block Kit[2019 south bay meetup] Building more contextual message with Block Kit
[2019 south bay meetup] Building more contextual message with Block KitTomomi Imura
 
Test-Driven Documentation for your REST(ful) service
Test-Driven Documentation for your REST(ful) serviceTest-Driven Documentation for your REST(ful) service
Test-Driven Documentation for your REST(ful) serviceJeroen Reijn
 
Aws Lambda Cart Microservice Server Less
Aws Lambda Cart Microservice Server LessAws Lambda Cart Microservice Server Less
Aws Lambda Cart Microservice Server LessDhanu Gupta
 
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...The Magic Revealed: Four Real-World Examples of Using the Client Object Model...
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...SPTechCon
 
MIKE Stack Introduction - MongoDB, io.js, KendoUI, and Express
MIKE Stack Introduction - MongoDB, io.js, KendoUI, and ExpressMIKE Stack Introduction - MongoDB, io.js, KendoUI, and Express
MIKE Stack Introduction - MongoDB, io.js, KendoUI, and ExpressCharlie Key
 
Open shift enterprise 3.1 paas on kubernetes
Open shift enterprise 3.1   paas on kubernetesOpen shift enterprise 3.1   paas on kubernetes
Open shift enterprise 3.1 paas on kubernetesSamuel Terburg
 
Serverless - Developers.IO 2019
Serverless - Developers.IO 2019Serverless - Developers.IO 2019
Serverless - Developers.IO 2019Shuji Watanabe
 
A 60-mn tour of AWS compute (March 2016)
A 60-mn tour of AWS compute (March 2016)A 60-mn tour of AWS compute (March 2016)
A 60-mn tour of AWS compute (March 2016)Julien SIMON
 

Ähnlich wie RESTful Api practices Rails 3 (20)

Enter the app era with ruby on rails (rubyday)
Enter the app era with ruby on rails (rubyday)Enter the app era with ruby on rails (rubyday)
Enter the app era with ruby on rails (rubyday)
 
Enter the app era with ruby on rails
Enter the app era with ruby on railsEnter the app era with ruby on rails
Enter the app era with ruby on rails
 
Building RESTful APIs w/ Grape
Building RESTful APIs w/ GrapeBuilding RESTful APIs w/ Grape
Building RESTful APIs w/ Grape
 
Building APIs in an easy way using API Platform
Building APIs in an easy way using API PlatformBuilding APIs in an easy way using API Platform
Building APIs in an easy way using API Platform
 
Symfony + GraphQL
Symfony + GraphQLSymfony + GraphQL
Symfony + GraphQL
 
Graphql + Symfony | Александр Демченко | CODEiD
Graphql + Symfony | Александр Демченко | CODEiDGraphql + Symfony | Александр Демченко | CODEiD
Graphql + Symfony | Александр Демченко | CODEiD
 
JSON REST API for WordPress
JSON REST API for WordPressJSON REST API for WordPress
JSON REST API for WordPress
 
iOS Swift application architecture
iOS Swift application architectureiOS Swift application architecture
iOS Swift application architecture
 
Building Better Web APIs with Rails
Building Better Web APIs with RailsBuilding Better Web APIs with Rails
Building Better Web APIs with Rails
 
From System Engineer to Gopher
From System Engineer to GopherFrom System Engineer to Gopher
From System Engineer to Gopher
 
REST easy with API Platform
REST easy with API PlatformREST easy with API Platform
REST easy with API Platform
 
AtlasCamp2014: Introducing the Confluence REST API
AtlasCamp2014: Introducing the Confluence REST APIAtlasCamp2014: Introducing the Confluence REST API
AtlasCamp2014: Introducing the Confluence REST API
 
[2019 south bay meetup] Building more contextual message with Block Kit
[2019 south bay meetup] Building more contextual message with Block Kit[2019 south bay meetup] Building more contextual message with Block Kit
[2019 south bay meetup] Building more contextual message with Block Kit
 
Test-Driven Documentation for your REST(ful) service
Test-Driven Documentation for your REST(ful) serviceTest-Driven Documentation for your REST(ful) service
Test-Driven Documentation for your REST(ful) service
 
Aws Lambda Cart Microservice Server Less
Aws Lambda Cart Microservice Server LessAws Lambda Cart Microservice Server Less
Aws Lambda Cart Microservice Server Less
 
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...The Magic Revealed: Four Real-World Examples of Using the Client Object Model...
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...
 
MIKE Stack Introduction - MongoDB, io.js, KendoUI, and Express
MIKE Stack Introduction - MongoDB, io.js, KendoUI, and ExpressMIKE Stack Introduction - MongoDB, io.js, KendoUI, and Express
MIKE Stack Introduction - MongoDB, io.js, KendoUI, and Express
 
Open shift enterprise 3.1 paas on kubernetes
Open shift enterprise 3.1   paas on kubernetesOpen shift enterprise 3.1   paas on kubernetes
Open shift enterprise 3.1 paas on kubernetes
 
Serverless - Developers.IO 2019
Serverless - Developers.IO 2019Serverless - Developers.IO 2019
Serverless - Developers.IO 2019
 
A 60-mn tour of AWS compute (March 2016)
A 60-mn tour of AWS compute (March 2016)A 60-mn tour of AWS compute (March 2016)
A 60-mn tour of AWS compute (March 2016)
 

RESTful Api practices Rails 3

  • 2. One Backend Multiple Clients Web Front-end Mobile (backbone.js, (Android, iOS, javascriptmvc.js etc.) BlackBerry, Symbian, WP7?) Third party applications
  • 3. API planning • RESTful - no-brainer for Rails people • Minimum viable API - Released features must be maintained and probably supported in next versions • Versioning - URI design • Formats - Json ... (xml?) • Authentication
  • 4. Versioning From the client side • URI design • www.myapp.com/api/v1 • api.myapp.com/v1 • Custom header X-SMTH-Api-ver: 1
  • 5. Versioning From the back-end • Sub-controllers • app/controllers/api/v1/ • app/controllers/api/v2/ • Routes • Models - mixins
  • 6. Request and response formats respond_with method in Rails 3
  • 7. Authentication • Session based - Devise • Request based - client provides his ID and a signature
  • 8. Testing     describe "post create" do Create Post       describe "when post is valid" do [POST] /api/v1/post.json         it "should respond with created" [PROPERTIES]         it "should respond with created post" • post: this object specifies the data to be created as a post (required) • third_party_id (required)         it "should have only allowed attributes in response object" • content (required)       end [EXAMPLE REQUEST]       describe "when post is invalid" do POST http://cannedapps.com:3838/api/post.json          "post": {         it "should respond with unprocessable entity" "third_party_id": 142, "content": "Hi Guys!"       end }     end On Success: Http status code 201 is returned, with a response body including the created participant id. [EXAMPLE RESPONSE] { "id": 767, "third_party_id": 142, "content": "Hi Guys!", "updated_at": "2011-04-14 07:18:43" } If a create or update action failed, HTTP status code 422 Unprocessable Entity and a JSON-encoded body of localized error messages will be returned.
  • 10. Thank you! Anton Narusberg Cannedapps github.com/naru anton@cannedapps.com @antonnarusberg

Hinweis der Redaktion

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n