Skip to content

Instantly share code, notes, and snippets.

@picsoung
Created October 14, 2013 13:29
Show Gist options
  • Save picsoung/6975640 to your computer and use it in GitHub Desktop.
Save picsoung/6975640 to your computer and use it in GitHub Desktop.

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

  • EngineYard command line tool link optional

Steps

  1. Follow Steve's tutorial 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

```
  1. 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
  2. Rename sentiment.rb in app/api/sentiment/ to ress.rb and edit the file so it looks like this

    module Sentiment
      class Ress < Grape::API
    	# Keep API logic like before
      end
    end
  3. Now edit config/application.rb and add those lines to load all the new files added

    config.paths.add "app/api", :glob => "**/*.rb"
    config.autoload_paths += Dir["#{Rails.root}/app/api/*"]
  4. Finally modify your routes.rb so it mounts the API class

    mount API => '/'
  5. 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment