APIs should be easy to develop and deploy, that's our goal at 3scale. In the past, Steve recorded a video tutorial showing how easy it is to create an API using GRAPE Ruby framework and deploy on Heroku.
Today I wanted to show you, that APIs are platform agnostic and deploying to EngineYard is simple.
Requirements :
-
Follow Steve's tutorial to create a simple API using Grapet. Come back here when it is ready to deploy.
-
We are going to create Rails app and include our API in it, create a new 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 folder
If you followed the tutorial that what you should have in your app
folder
```bash
$ 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 load all the 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 version 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 :)
-
Go modify the back-end url of your API in your 3scale Dashboard.