Search code examples
ruby-on-railsrubyrubygemsrails-engines

How do i enhance rails gem to serve endpoints


I'm new to rails, I am reading through the documentation and trying to figure-out how can i enhance existing gem so i can add few end points which can be consumed from the client applications (angular apps, vue apps, react apps).

Example:

  1. I have existing gem called book_scheduler. looking at this it doesn't have app or config folder structure but bin and lib.

  2. Now i would like to enhance the gem to have two endpoints, so the clients can call book/count and book/return using fetch.

How can i accomplish this ? Can i somehow enhance the gem to have rails engine and define routes ? Any advice or guidance is much appreciated.


Solution

  • If you wan to use book_scheduler in many rails application, you can make it an Engine It will help you to cerate many rails application with the same endpoints

    But if you want to build a single rails API (used by multiple client apps), you should do the following :

    • include your gem in your project with bundler
    • define your endoints in routes.rb
    • create a controller that implement the endoints based on existing gem
    • create your views if needed. Or simply render in JSON