(Cheatsheet with no coding or local installations needed in approximately 15 minutes)
##Intro
Here are some instructions to build and deploy a RESTful JSON API. Backed by Rails and a SQL database (postgresql), deployed to heroku, and publically accessible. There are 3 quick & easy steps:
- use prelang.com to scaffold a rails app on your github account, based on a data model (entity relationship model) of your choice
- use cloud9.io to access the code and prepare it to be deployed to Heroku.
- Heroku: a platform as a service (PaaS) that enables developers to build, run, and operate applications entirely in the cloud.
1. prelang.com
Prelang is an automated rails building tool
- Go to prelang.com and Sign-in w/GitHub
- Create New Project
- Name
- Select DB: PostgreSQL
(PostgreSQL REQUIRED, 5432) - Add Feature
◊ Add Scaffolding (Future "Ambitious" use P3: Demo Video; RAILS. Add 'User Login', without code. Uses GUI in "Models")
NOTE: 'Scaffolding' is fine for practice/learning, bad practice when charging users. - Add Model
'Post'
◊ String: title (100s char limit)
◊ Text: description (166 char limit)
◊ URL: link
(Future "Ambitious" use: Add Comment; Text: commentBody, BelongsTo: Post > Post>>HasMany: Comment)
◊ Scaffold: ON - Generate Project
Auto-pushes to GitHub (URL) and creates a repo for you.
2. c9.io
Cloud 9 is a hosted development environment with all the tools you need to work on a Rails project, so that you need not install Ruby/Rails on your local machine.
- Go to Cloud 9, log in.
- Create a new workspace
- Workspace name:
◊ Name: ________
◊ Description: ________
◊ Clone from Git (Use the github url that prelang generated.) - Template: Rails
◊ Create workspace (You should now see your Rails project code.) - Navigate to app/controllers
◊ application_controller.rb
◊ Change~ :exception > :null_session (Default: Ln4)
◊ Ctrl + S (There is no Auto-save) - Open TERMINAL:
$ git add -A
$ git commit -m "Makes: available with null_session"
$ git push origin master
AUTH: User Id & Pass (Unless SSH configured)
###3. heroku.com
Heroku will host our newly created Rails app live on the web so that we can interact with it. It will also give us a PostgreSQL database.
- Go to heroku and log in
- Create a new app in the heroku GUI.
Make a note of the app name (referred to later as instancename) - TERMINAL (in Cloud 9)
◊ heroku login
AUTH: User Id & Pass
$ heroku git: remote -a instancename
$ git remote -v (recheck git)
$ git push heroku master
*Installs Gems… Ignore 'WARNING'*s (Ruby being fussy)
$ git remote -v (you should now see a new remote for heroku)
$ bundle install
$ heroku run rake db:migrate
Like gradle for Rails; executes SQL commands
That's it! You should have a working API deployed to the web.
You can now navigate to: instancename.heroku.com/modelname
Or just use this as an API
In addition you will be able to interact with this DB through your web browser:
- BROWSER:
instancename.heroku.com/modelname (plural) - Editing Post
◊ Title
◊ Description
◊ Link - Create Post
instancename.heroku.com/posts.json
Displays full RESTful json. - TERMINAL:
$ rake routes - POSTMAN
◊ POST instancename.herokuapp.com/posts.json
◊ Body
◊ raw
◊ JSON (application/json)
{ "title" : "test"
"description : " testing",
"link" : "insert_valid_link_post"
} - GET instancename.herokuapp.com/posts/2.json
Returns json