preloader
心得

Roles of grape gem and other related gem for building API service | Grape 與其它相關建立API工具的角色

Grape gem is the core of API service, which bulits API endpoints and handles each exception. Devise gem’s role is the user management system. Doorkeeper gem manages oauth clients, which are related with users in Devise gem, and record oauth clients' app id, secret, scopes, authorization codes and access tokens. Doorkeeper takes responsibilities about giving, revoking, and refreshing authorization codes and access tokens. Wine_bouncer gem’s role is a guard of API endpoints, which exams an access tokens with every request that receiving from oauth clients. Grape-swagger and grape-swagger-rails(used as swagger-ui) gem are used for writting documents of API usage.

 

I think these are all you need to learn for building a basic API-service. 

Tips:

  • Must place rescue_from statements, which belong to exception-handling statements, before- and after-statements prior to mount-statements. That’s what I had faced with dealing exception-handling ones. [This comes from https://github.com/ruby-grape/grape/issues/646 Grape’s issues #646]
  • Don’t forget to read WiKis and issues of Grape, Devise and Doorkeeper gem at github.com because there are useful.
  • If you prefer to write documents of API in your own format and style instead of swagger and swagger-ui style, you could ignore the grape-swagger and grape-swagger-rails gem.