The Google Cloud SQL Admin API is built on HTTP and JSON, so any standard HTTP client can send requests to it and parse the responses. However, instead of creating HTTP requests and parsing responses manually, you may want to use the Google APIs client libraries. The client libraries provide better language integration, improved security, and support for making calls that require user authorization.
Contents
Accessing the service
Depending on the Google Cloud SQL Admin API client library you use,
you may need to configure how the library
discovers the default service path. For client libraries that use the Google APIs Discovery
Service, use the API name
sqladmin
to build a client. This includes libraries for
Python and JavaScript.
The following code snippets, show how to create a client and list Cloud SQL instances in a project.
Java
For the Client Library for Java , you can optionally specify the service path directly.
// set up global SQLAdmin instance client = new SQLAdmin.Builder(httpTransport, JSON_FACTORY, credential) .setServicePath("sql/v1beta3/projects/") .setApplicationName(APPLICATION_NAME).build(); InstancesListResponse resp = client.instances().list("PROJECT_ID").execute(); List<DatabaseInstance> list = resp.getItems(); for (DatabaseInstance d : list) { System.out.println(d.getInstance()); }
JavaScript
For the
Client Library for JavaScript
,
specify
sqladmin
to build a client.
gapi.client.load('sqladmin', 'v1beta3', function() { console.log('loaded');}); gapi.client.sql.instances.list({'project': PROJECT_ID}).execute(showResult); function showResult(result) { // Process the result. };
Python
For the
Client Library for Python
,
specify
sqladmin
to build a client.
# Construct the service object for the interacting with the Cloud SQL Administration API. service = discovery.build('sqladmin', 'v1beta3', http=http) req = service.instances().list(project="PROJECT_ID") resp = req.execute() print json.dumps(resp, indent=2)
The
service
object queries the discovery document and use the correct
service path, in this case, "sql/v1beta3/projects/".
List of libraries and samples
In the tables below, the first column shows each library's stage of development (note that some are in early stages), and links to documentation for the library. The second column links to available samples for each library.
These early-stage libraries are also available:
Documentation | Samples |
---|---|
Google APIs Client Library for Go (alpha) | Go samples |
Google APIs Client Library for Node.js (alpha) | Node.js samples |
Google APIs Client Library for Ruby (alpha) | Ruby samples |
In addition to the Google-supported client libraries listed in the table above, a set of third-party Dart libraries (with samples ) is available for the Dart language .