Before you begin

Note: If you don't plan on keeping the GCP resources
that you create during this tutorial, create a new project. After you finish, you can
delete the project, removing all resources associated with the project and
tutorial.

Run the server locally

In the /stickynoteapi/REST/Go directory, run the following command:

sh SETUP

The command displays the following output:

1. Set gopath and search path
2. Get the server and client dependencies
3. Build the server and client
4. Stop any previously-running instances of the server
5. Start the server
6. Run the client
2016/03/02 11:34:48 OK: message.png
7. Open the image in message.png

The setup also runs a local client to test the server with the phrase "Remember
the milk". The server generates a message.png file that contains the
corresponding image.

To generate images based on your own messages using the command-line client,
run the following command:

./client "This is a test..."

The /stickynoteapi/REST/Go/go/src/server/server.go file contains the code that
runs the REST server. The main function defines a handler for the root-level
directory and listens for traffic on port 8080.

When you tap Return after entering your message in the text field, the app
encodes the message into a query string and sends it to the server in a REST
request. The app receives the REST response, extracts the generated image, and
displays it in an image view. The following code shows the action that handles
these tasks:

An image of a yellow sticky note with your message replaces the gray background.

Cleaning up

To avoid incurring charges to your Google Cloud Platform account for
the resources used in this tutorial:

Deleting the project

The easiest way to eliminate billing is to delete the project you
created for the tutorial.

To delete the project:

Caution: Deleting a project has the following effects:

Everything in the project is deleted. If you used an existing project for
this tutorial, when you delete it, you also delete any other work you've done in the project.

Custom project IDs are lost.
When you created this project, you might have created a custom project ID that you want to use in
the future. To preserve the URLs that use the project ID, such as an appspot.com
URL, delete selected resources inside the project instead of deleting the whole project.

If you plan to explore multiple tutorials and quickstarts, reusing projects can help you avoid
exceeding project quota limits.

Deleting firewall rules for the default network

Click the Delete button at the top of the page to
delete the firewall rule.

What's next

This sample demonstrates the basics of how to connect a mobile app to code
running on Compute Engine using REST. To extend this sample into a real app,
consider adding the following enhancements:

Add a static external IP address to your server -- by default, the
external address associated with a Compute Engine instance is transient. In a
production app, attach a static external IP address to your instance. For more
information, see Configuring an Instance’s IP
Address.

Use credentials to connect to an HTTPS server -- ensure that your
backend service can be called only by your mobile app by requiring your mobile
app to use credentials to authenticate itself to the server. Protect the
privacy of the data that your users send to the server, by using the encrypted
HTTPS protocol instead of HTTP. To do this you could run a NGINX server as an
SSL proxy on your instance or run your backend server in the App Engine
flexible environment. For more information, see Securely Connecting to VM
Instances.

Explore using the gRPC protocol instead of REST --
gRPC is a framework that makes it possible for a
mobile app to directly call methods on a backend service as if it was a local
object. You can use gRPC to make your mobile app more bandwidth-efficient and
to reduce latency between your app and backend service running on GCP. For an
example of how to use gRPC in the Stickynotes sample, see Build a mobile app
using Google Compute Engine and gRPC

Consider other hosting options for your backend service -- Compute Engine
offers the greatest degree of control over your virtual machine, but at the
cost of you manually updating and managing your instance. For a discussion of
other ways to host a mobile backend service on Cloud Platform, see Build
mobile apps using Google Cloud
Platform.