Upgrade to Pro — share decks privately, control downloads, hide ads and more …

RESTful API with Grape

RESTful API with Grape

Charles Lalonde

May 20, 2016
Tweet

Other Decks in Programming

Transcript

  1. Why Grape? • Framework to build API • Easily extensible

    • Supports Rails, Sinatra 
 and others
  2. • app/ • api/ • v1/ • base.rb Create folder

    structure Setup Rails in 4 simple steps
  3. Setup Rails in 4 simple steps • Versioning • Format

    • Endpoint mounting • Default headers • Logs
  4. { Grape } Basic • Call Overview • Headers •

    Parameters • Http Methods • Error Handling • Helpers
  5. Overview • Resource • Route params • HTTP methods •

    Parameters GET api.montrealrb.com/v1/:resource/:route_param
  6. Headers • Useful for bots • Alerting users of deprecated

    endpoints • Allow multiple origins • etc
  7. { Grape } gem extension WineBouncer 
 Oauth2 protection with

    Doorkeeper
 https://github.com/antek-drzewiecki/wine_bouncer grape-rails-cache
 Server side cache
 https://github.com/monterail/grape-rails-cache grape-swagger
 Automatically generate documentation
 https://github.com/ruby-grape/grape-swagger
  8. Unsplash API Stats API Requests 230 740 265 Last 30

    days API Developers 2 479 Approved Applications 184