RESTful API with Grape

RESTful API with Grape

C4632f4ce0cf63e66d0bb89bce4b0369?s=128

Charles Lalonde

May 20, 2016
Tweet

Transcript

  1. RESTful API with Grape

  2. Hi, I’m Charles Rails Developer @ Unsplash

  3. Unsplash Do whatever you want high-resolution photos

  4. None
  5. None
  6. None
  7. None
  8. None
  9. None
  10. Why Grape?

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

    • Supports Rails, Sinatra 
 and others
  12. Setup Rails in 4 simple steps

  13. • app/ • api/ • v1/ • base.rb Create folder

    structure Setup Rails in 4 simple steps
  14. Setup Rails in 4 simple steps Auto load the API

    files in your application.rb
  15. Mount the API in routes.rb Setup Rails in 4 simple

    steps
  16. Setup Rails in 4 simple steps • Versioning • Format

    • Endpoint mounting • Default headers • Logs
  17. { Grape } Basic

  18. { Grape } Basic • Call Overview • Headers •

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

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

    endpoints • Allow multiple origins • etc
  21. Parameters • Can manage optional and required params • Multiple

    parameter types • Custom validation
  22. HTTP methods • Supports all HTTP methods • Specify endpoint

    names
  23. Error handling • Message • Status

  24. Helpers • Create reusable code • Can include custom modules

  25. { Grape } gem extension

  26. { 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
  27. { Grape } gem extension

  28. Demo

  29. Unsplash API Stats API Requests 230 740 265 Last 30

    days API Developers 2 479 Approved Applications 184
  30. Connect @dechuck on Twitter, GitHub & Unsplash Thanks