Hello.
I'm Jonathan Simon with the Google Cloud Platform team.
I'm going to talk to you about Google Cloud Storage, and how
you can use JavaScript to start building on top of
Google's powerful storage infrastructure.
Cloud Storage is a fast, scalable, and reliable storage
service offered by Google as part of its Cloud platform.
For more details about Cloud Storage, here are two links to
help you get started.
I'm going to show you a demo of a Cloud Storage sample
application that uses the JavaScript client library for
Google APIs.
The Google JavaScript client library provides access from
the JavaScript environment to Cloud Storage and many other
Google APIs.
Just add the script tag you see here to your HTML to
include the Google JavaScript API client library.
Now that you know how to include the JavaScript client
library in your HTML, the next thing to do is to grab the
code for the Cloud Storage JavaScript sample application.
Since the source control for the samples code is using Git,
the checkout command is git clone, and then the name of
the GitHub repository.
The next thing you want to do is navigate into the directory
containing the JavaScript sample code.
Just copy and paste that CD command into your terminal.
Then you'll want to follow through the README, and enter
the details in the index.html file.
That will include your Google Cloud Storage project ID, your
client ID, and your API key.
After that, you can load it up on a web server
and see it in action.
A quick way to start a simple web server to view the demo is
by using Python's built-in server.
So let's switch over to a terminal
window and try it out.
You can see that I'm in the Storage Getting Started
JavaScript directory.
And if we list the files there, you can see the
index.html file, which I've already updated to include my
applications details.
To start serving index.html from a web server, we can
simply type Python -m simpleHTTPserver.
There, now the Python web server is running.
Notice that the default port that it is serving
pages from is 8,000.
So we can open up our browser and enter
http://localhost:8000 to load the sample.
Here's the cloud storage sample application using the
JavaScript client library.
If this is your first time signing in, you'll see an
Authorize button in the top-left corner of the screen.
And when you click that button, it will request
permission to access your cloud storage resources.
When you click Accept and complete the authorization
process, you can try out a sample API call.
Let's start by listing all the buckets that are currently
available for my project in cloud storage.
So this sample application returns a few pieces of
information, including an explanation of the selected
API request, a bit of code that's generated for the
request, and the API's response to
the request we made.
So if we look at the explanation, we can see that
we're querying the Google Cloud Storage API for a list
of buckets and returning that list.
Looking at the code, you can see how we construct our
parameter object and initialize a single parameter
to that which is then passed to the Google
Cloud Storage API.
Looking at the API response, which is formatted in JSON, we
can see we're getting back a list of buckets.
But we don't currently have any buckets in there, so let's
go ahead and insert a bucket.
Here's a bit of information about the request.
Here's the JavaScript code that you can copy and paste
directly into your code.
Notice that we specified code-sample-test-bucket as the
ID of the bucket to be inserted, and
here's the API's response.
Now let's go back to List Buckets to make sure that we
actually inserted that bucket.
And indeed, we can see that our items
array now has one bucket.
And the ID of that bucket is code-sample-test-bucket.
Excellent.
We could do more than just list and insert buckets.
We can also list a bucket's access control list.
We can list and insert objects, and more.
This sample is showing a subset of all the API commands
available to help you understand the look and feel
of making a JavaScript request to the Google
Cloud Storage API.
Check out the cloud storage documentation for the full
list of commands.
Now why don't we take a look at the codes so we can really
understand what the request looks like in JavaScript.
So if we open up index.html in an editor and look up a
function like listBuckets, that's all there is to it.
You can see we put together a request.
And we pass in the project ID for the project that we'd like
to list buckets for, and then we execute the request.
Looking at the executeRequest function, you can see it
accepts two arguments-- a request object, and the name
of the API request being made.
Stepping into the function, first we execute the request.
And then using a JavaScript function literal, we output
the response to the HTML page which you can see by jumping
down into the function.
We create HTML pre-elements, and then we output the
response to the inner HTML of that pre-element using
JSON.stringify.
And then finally, we append that pre-element to a div
element that's visible on the HTML page.
Let's review the workflow for using the
JavaScript client library.
The first thing you'll do is include the
Google JavaScript APIs.
Just script that source.
Then you can include or load the Google API of your choice.
Here we're including the Cloud Storage API.
And finally, you can make
requests and display responses.
It's as easy as that.
To wrap up, here are a few more resources where you can
go to learn more.
If you have any questions or feedback, please feel free to
reach out to us on Stack Overflow or via email.
Thank you for watching.
Now that you've seen how easy it is to get started, go ahead
and try out the Cloud Storage
JavaScript sample for yourself.