Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a REST API for an existing Ruby on Rails 5 application?

I have a Rails 5 app with ActionCable and Devise gem hosted on Heroku with 15K users. Many users have suggested to release a mobile app for the website. I want to start by creating a basic mobile app for the website.

When I google, all I get is API only guide. Are there any tutorials or books or any resource that show how to create a REST API for an existing Rails app?

Can someone kindly guide on how to do this? How do I authenticate users? How do I use real-time chat? Should I use any gem? Kindly share how to start and the best practices. Thanks

like image 633
LovingRails Avatar asked Jul 28 '16 19:07

LovingRails


2 Answers

Are there any tutorials or books or any resource that show how to create a REST API for an existing Rails app?

Yes. This Railscast is very helpful. He goes through how to set up the basic parts of a restful API for an already functioning (albeit very simple) Rails app.

It's a few years old, but should still work for Rails 5.

like image 170
user3680688 Avatar answered Sep 22 '22 14:09

user3680688


I spent days trying to figure this out myself. Eventually I was able to do it using the gems 'grape', 'rack-cors', and 'grape-active_model_serializer' and wrote up a quick tutorial. Should work for Rails 5.2 and 6.0. You can check it out here: https://medium.com/@ryanwaldorf/how-to-add-an-api-to-an-existing-rails-app-1d2419ba91bd

Hope this helps everyone!

like image 25
Ryan Waldorf Avatar answered Sep 22 '22 14:09

Ryan Waldorf