RESTful Api practices Rails 3
Upcoming SlideShare
Loading in...5
×
 

RESTful Api practices Rails 3

on

  • 9,339 views

 

Statistics

Views

Total Views
9,339
Views on SlideShare
9,339
Embed Views
0

Actions

Likes
4
Downloads
52
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n

RESTful Api practices Rails 3 RESTful Api practices Rails 3 Presentation Transcript

  • 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
  • VersioningFrom the client side • URI design • www.myapp.com/api/v1 • api.myapp.com/v1 • Custom header X-SMTH-Api-ver: 1
  • VersioningFrom 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" doCreate 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" doPOST http://cannedapps.com:3838/api/post.json          "post": {         it "should respond with unprocessable entity" "third_party_id": 142, "content": "Hi Guys!"       end }     endOn Success:Http status code 201 is returned, with a response body including the createdparticipant 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 Entityand a JSON-encoded body of localized error messages will be returned.
  • Examplehttps://github.com/naru/API-practices-demo
  • Thank you! Anton Narusberg Cannedapps github.com/naruanton@cannedapps.com @antonnarusberg