Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Grape(Ruby on Rails)

735 views

Published on

This presentation is on 'Grape', which is an opinionated micro-framework for creating REST-like APIs in Ruby. For details, visit

http://intridea.github.io/grape

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Grape(Ruby on Rails)

  1. 1. Building an API using GRAPE Presented By- Md. Main Uddin Rony
  2. 2. Outlines What’s Grape? Basic API Add Prefix Add Namespace Add Module Add version Parameters Declared Using Helpers Routes Raise Exception Exception Handling API Format Useful Resources
  3. 3. What’s Grape?
  4. 4. Generalized Rapid APIs Erector
  5. 5. An opinionated micro-framework for creating RESTful APIs in Ruby
  6. 6. •Powerful API framework •Designed to run on Rack Application •To fit into Sinatra and Rails Application
  7. 7. Installation ‘ gem install grape’ Or gem 'grape‘ // using Bundler Run bundle install.
  8. 8. Work with Rails Place API files into and modify Modify
  9. 9. Basic API
  10. 10. Add Prefix
  11. 11. Add Namespace
  12. 12. Add Namespace (Contd.) Namespaces allow parameter definitions and apply to every method within the namespace.
  13. 13. Add Namespace(Contd.) We can define a route parameter as namespace using
  14. 14. Add Module If we want to mount on a path inside the mounted API itself:
  15. 15. Add Version
  16. 16. Add Version(Contd.) Four Strategies: ❑ Path → → ❑ Header → → ❑ Param → → → ❑ Accept-Version Header → →
  17. 17. Parameters Request parameters are available through the ”params” hash object. Parameters are automatically populated from the request body on POST and PUT for form input, JSON and XML content-types.
  18. 18. Declared Grape allows you to access only the parameters that have been declared by your ’params’ block. It filters out the params that have been passed, but are not allowed.
  19. 19. Use Helpers
  20. 20. Routes We can define requirements for your named route parameters using regular expressions on namespace or endpoint.
  21. 21. Raise Exception We can abort the execution of an API method by raising errors with We can also return JSON formatted objects by raising error! and passing a hash instead of a message.
  22. 22. Exception Handling Grape can be told to rescue all exceptions and return them in the API format. You can also rescue specific exceptions.
  23. 23. API Formats If we do not specify any, Grape will support XML, JSON, BINARY, and TXT content-types. The default format is :txt
  24. 24. Advantages 1. Designed to run on rack or existing application frameworks such as Rails and Sinatra 2. It has built-in support for common conventions, including multiple formats, subdomain/prefix restriction. 3. Versioning is very easy. 4. A lightweight framework which is loosely coupled with other application frameworks.
  25. 25. Useful Resources 1. https://github.com/intridea/grape 2. https://groups.google.com/forum/?fromgroups#!forum/ruby-grape 3. http://intridea.github.io/grape/docs/index.html 4. https://github.com/intridea/grape/wiki 5. http://confreaks.tv/videos/rubyconf2010-the-grapes-of-rapid
  26. 26. Questions??
  27. 27. THANK YOU!!!!

×