Rapid-ruby-api-on-grape

39
Copyright 2010, Intridea Inc. All Rights Reserved. Rapid Ruby API On Grape [email protected] 2011/07/24

description

this presentation is for a Rails Meetup event which happened on July 24th 2011, Beijing.

Transcript of Rapid-ruby-api-on-grape

Page 1: Rapid-ruby-api-on-grape

Copyright 2010, Intridea Inc. All Rights Reserved.

Rapid Ruby API On Grape ���

[email protected] 2011/07/24

Page 2: Rapid-ruby-api-on-grape

Copyright 2010, Intridea Inc. All Rights Reserved.

About Me   Symbol - yorzi Details - about.me/wangyaodi Senior Engineer at Intridea Inc.

More Links:   http://github.com/yorzi   http://twitter.com/yorzi   http://more-sites/yorzi

王要弟 Andy Wang

Page 3: Rapid-ruby-api-on-grape

Copyright 2010, Intridea Inc. All Rights Reserved.

What’s Grape?

Page 4: Rapid-ruby-api-on-grape

Copyright 2010, Intridea Inc. All Rights Reserved.

Page 5: Rapid-ruby-api-on-grape

Copyright 2010, Intridea Inc. All Rights Reserved.

https://github.com/mbleigh https://github.com/intridea/omniauth

https://github.com/mbleigh/acts-as-taggable-on

Page 6: Rapid-ruby-api-on-grape

Copyright 2010, Intridea Inc. All Rights Reserved.

Ok, BUT���What’s Grape?

Page 7: Rapid-ruby-api-on-grape

Copyright 2010, Intridea Inc. All Rights Reserved.

“An opinionated ���micro-framework ���

for creating REST-like��� APIs in Ruby”

https://github.com/intridea/grape http://www.infoq.com/articles/rest-introduction

Page 8: Rapid-ruby-api-on-grape

Copyright 2010, Intridea Inc. All Rights Reserved.

Ruby makes hard things easy

Page 9: Rapid-ruby-api-on-grape

Copyright 2010, Intridea Inc. All Rights Reserved.

But APIs still aren’t easy

Page 10: Rapid-ruby-api-on-grape

Copyright 2010, Intridea Inc. All Rights Reserved.

APIs in Rails are too entangled

Page 11: Rapid-ruby-api-on-grape

Copyright 2010, Intridea Inc. All Rights Reserved.

APIs in Sinatra are too manual

Page 12: Rapid-ruby-api-on-grape

Copyright 2010, Intridea Inc. All Rights Reserved.

Page 13: Rapid-ruby-api-on-grape

Copyright 2010, Intridea Inc. All Rights Reserved.

Page 14: Rapid-ruby-api-on-grape

Copyright 2010, Intridea Inc. All Rights Reserved.

How To Use Grape?

Page 15: Rapid-ruby-api-on-grape

Copyright 2010, Intridea Inc. All Rights Reserved.

Page 16: Rapid-ruby-api-on-grape

Copyright 2010, Intridea Inc. All Rights Reserved.

Remember: ���Grape APIs are

Rack applications

http://ruby.about.com/od/rack/a/What-Is-Rack.htm

Page 17: Rapid-ruby-api-on-grape

Copyright 2010, Intridea Inc. All Rights Reserved.

Basic API

Page 18: Rapid-ruby-api-on-grape

Copyright 2010, Intridea Inc. All Rights Reserved.

Result,���JSON Serialization

Page 19: Rapid-ruby-api-on-grape

Copyright 2010, Intridea Inc. All Rights Reserved.

Add Prefix

Page 20: Rapid-ruby-api-on-grape

Copyright 2010, Intridea Inc. All Rights Reserved.

Add Version ���

Page 21: Rapid-ruby-api-on-grape

Copyright 2010, Intridea Inc. All Rights Reserved.

Add Namespace ���

Page 22: Rapid-ruby-api-on-grape

Copyright 2010, Intridea Inc. All Rights Reserved.

Other Namespacing ���Key words

Page 23: Rapid-ruby-api-on-grape

Copyright 2010, Intridea Inc. All Rights Reserved.

Add Basic Auth ���

Page 24: Rapid-ruby-api-on-grape

Copyright 2010, Intridea Inc. All Rights Reserved.

Use Helpers ���

Page 25: Rapid-ruby-api-on-grape

Copyright 2010, Intridea Inc. All Rights Reserved.

Raise Error ���

Page 26: Rapid-ruby-api-on-grape

Copyright 2010, Intridea Inc. All Rights Reserved.

Error Details

Page 27: Rapid-ruby-api-on-grape

Copyright 2010, Intridea Inc. All Rights Reserved.

How To ���Run Grape APIs?

Page 28: Rapid-ruby-api-on-grape

Copyright 2010, Intridea Inc. All Rights Reserved.

Remember: ���Grape APIs are

Rack applications

Page 29: Rapid-ruby-api-on-grape

Copyright 2010, Intridea Inc. All Rights Reserved.

Run As a Rack App

Run `rackup` in Rack App(API) folder

Page 30: Rapid-ruby-api-on-grape

Copyright 2010, Intridea Inc. All Rights Reserved.

Grape with Rails 2.3.x

Page 31: Rapid-ruby-api-on-grape

Copyright 2010, Intridea Inc. All Rights Reserved.

Grape with Rails 3.x

Page 32: Rapid-ruby-api-on-grape

Copyright 2010, Intridea Inc. All Rights Reserved.

Any Future Feature?���YES!

Page 33: Rapid-ruby-api-on-grape

Copyright 2010, Intridea Inc. All Rights Reserved.

Near Future

*Support for XML formatting *Multiple-file APIs (modularity)

*OAuth 1.0a and 2.0 authentication support Filters/Callbacks

https://github.com/makandra/modularity http://code.dblock.org/modularizing-a-ror-grape-api

Page 34: Rapid-ruby-api-on-grape

Copyright 2010, Intridea Inc. All Rights Reserved.

Medium Future

YARD extensions for self-documenting APIs Plugin System for easy extension

Internal API Access Rate Limiting

Lifecycle Automation

Page 35: Rapid-ruby-api-on-grape

Copyright 2010, Intridea Inc. All Rights Reserved.

Far Future

Streaming API support PubSubHubBub

Page 36: Rapid-ruby-api-on-grape

Copyright 2010, Intridea Inc. All Rights Reserved.

Resources & References RubyConf 2010 presentation about Grape.

http://confreaks.net/videos/475-rubyconf2010-the-grapes-of-rapid

https://github.com/downloads/intridea/grape/The%20Grapes%20of%20Rapid.pdf

Example Rails implementation http://martinciu.com/2011/01/mounting-grape-api-

inside-rails-application.html

Page 37: Rapid-ruby-api-on-grape

Copyright 2010, Intridea Inc. All Rights Reserved.

Demo & Sample Demo API with Sinatra App.

https://github.com/mbleigh/conf_ask http://www.arailsdemo.com/posts/30

Well Documented Sample API. https://gist.github.com/892282

Page 38: Rapid-ruby-api-on-grape

Copyright 2010, Intridea Inc. All Rights Reserved.

Page 39: Rapid-ruby-api-on-grape

Copyright 2010, Intridea Inc. All Rights Reserved.

Thank You!