Created
October 14, 2013 13:29
Revisions
-
picsoung created this gist
Oct 14, 2013 .There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,92 @@ Deploy your API on EngineYard ============================= 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 : * Ruby * Rails * Grape framework [link](https://github.com/intridea/grape) * EngineYard command line tool [link](https://support.cloud.engineyard.com/entries/21009927-Deploy-from-the-CLI-Engine-Yard-CLI-User-Guide-) optional Steps ----- 1. Follow Steve's [tutorial](http://www.3scale.net/2012/06/the-10-minute-api-up-running-3scale-grape-heroku-api-10-minutes/) to create a simple API using Grapet. Come back here when it is ready to deploy. 2. We are going to create Rails app and include our API in it, create a new rails app `rails new my-app` 3. Create a directory `api` under `app` folder. That's where all your API logic will go. 4. 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 ``` 5. in `app/api/api.rb` ```ruby class API < Grape::API prefix 'api' # optional, it makes you api available at myserver.com/api/ mount Sentiment::Ress end ``` 6. Rename `sentiment.rb` in `app/api/sentiment/` to `ress.rb` and edit the file so it looks like this ```ruby module Sentiment class Ress < Grape::API # Keep API logic like before end end ``` 7. Now edit `config/application.rb` and add those lines to load all the new files added ```ruby config.paths.add "app/api", :glob => "**/*.rb" config.autoload_paths += Dir["#{Rails.root}/app/api/*"] ``` 8. Finally modify your `routes.rb` so it mounts the API class ```ruby mount API => '/' ``` 9. Your API should be ready to serve. Relaunch your server and try to access it at `http://localhost:3000/api/v2/words/hello.json` ## Deploy on Engineyard 1. Setup a new Application in your Cloud account and add deploy keys to it 2. Create a new environnement * passenger 3 * ruby version of your choice 3. Launch instance and deploy If the deploy breaks it generally coming from missing gems or assets configuration. 4. Your API should be accessible :) 5. Go modify the back-end url of your API in your 3scale Dashboard.