Data, Maps, Usability, and Performance

API on Google App Engine with Martini and Go

Last updated on August 20, 2014 in Development

GAE with Martini and Go

Google App Engine is a great platform for quickly developing and hosting web applications. There are alternatives but today we are going to dig into GAE and show how simple it is to get started. I have previously made a few posts on Go and Martini so today we are going to setup Martini on Google App Engine for the Go Language in order to launch an API in the cloud. Martini is a great framework for building a RESTful API and the workflow below will take you through all the steps, from downloading GoogleAppEngine to deploying our Martini API app:

1. Download and Install GAE for GO

2. Add Google App Engine to your PATH, I added this line to $HOME/.bash_profile: export PATH=”$HOME/personal/go_appengine:$PATH”

3. Verify that Google App Engine is installed: goapp version: (resulted in go version go1.2.1 (appengine-1.9.9) darwin/amd64)

4. Setup Hello World Example:

mkdir gae_go
cd gae_go
mkdir myapp
download example and copy zip files into myapp folder: app.yaml and hello.go

5. Verify Hello World example: goapp serve and check browser via http://localhost:8080

6. Lets make a new folder called api and copy both files in there:

cd ..
mkdir api
cp -rf myapp api

7. Lets change application name in app.yaml from helloworld to myapi

8. Lets change the hello.go file to use Martini:

package hello

import (
"net/http"
"github.com/go-martini/martini"
)

func init() {
m := martini.Classic()
m.Get("/", func() string {
return "Hello world!"
})
http.Handle("/", m)
}

9. Let grab Martini for Google App Engine: goapp get github.com/go-martini/martini

10. Verify that Martini is working by directing running the app (goapp serve) and checking the browser: http://localhost:8080/

Things worked out of the box. We have the foundation to start building out our API. Now, lets go through the steps to deploy the application:

1. Register the Application:
Project Name: Playing Cards API
Project ID: playing-cards-api

2. Lets change our app.yaml application from myapi to playing-cards-api

3. Lets upload the application: goapp deploy api

4. Verify that application is on Google App Engine: http://playing-cards-api.appspot.com/

How simple is that? As you might have guessed from the name, I will be building a RESTful API for playing cards. Stay tuned.

Tags: , , , ,

Facebook Twitter Hacker News Reddit More...