Embedded original Sentiment API build using Grape framework into a Rails app
$ git clone git@github.com:picsoung/sentiment-api-rails.git
$ cd sentiment-api-rails
$ bundle install
$ rails s
The API is available at http://localhost:3000/api/v2/words/hello.json
-
Follow @njyx's tutorial about how to implement a simple API using Grape framework and 3scale. link
-
Create an empty Rails app
rails new my-app
-
Create a directory
api
underapp
folder. That's where all your API logic will go. -
Create a empyt file
api.rb
in this new created folderIf you followed the tutorial that what you should have in your
app
folder$ ls app/ app |-- api.rb |-- sentiment/ | |-- analyser.rb | |-- sentiment.rb | |-- data/ | | |-- working_AFINN-111.txt
-
in
app/api/api.rb
class API < Grape::API prefix 'api' # optional, it makes you api available at myserver.com/api/ mount Sentiment::Ress end
-
Rename
sentiment.rb
inapp/api/sentiment/
toress.rb
and edit the file so it looks like thismodule Sentiment class Ress < Grape::API # Keep API logic like before end end
-
Now edit
config/application.rb
and add those lines to take load new files addedconfig.paths.add "app/api", :glob => "**/*.rb" config.autoload_paths += Dir["#{Rails.root}/app/api/*"]
-
Finally modify your
routes.rb
so it mounts the API classmount API => '/'
-
Your API should be ready to serve. Relaunch your server and try to access it at
http://localhost:3000/api/v2/words/hello.json
-
Setup a new Application in your Cloud account and add deploy keys to it
-
Create a new environnement
- passenger 3
- ruby of your choice
-
Launch instance and deploy If the deploy breaks it generally coming from missing gems or assets configuration.
-
Your API should be accessible :)