The Cloud Endpoints API comes packaged with endpointscfg.py to generate client libraries in JavaScript, Objective-C (for iOS) and Java (for Android). You can also generate a few additional client libraries using the Google APIs client generator. This article will show you how to use the generator to create a C# client library.
The client generator is a Python application you can install with pip
.
pip install google-apis-client-generator
The client generator works by taking an API discovery document, parsing it into an object model, and then using a language template to transform the object model to running code.
To run the generator you will need the discovery document for your API. You can find this document from the root API discovery URL. First, download the root API discovery document using httpie.
http --download https://example.appspot.com/_ah/api/discovery/v1/apis
"items": [
{
"description": "Example Api",
"discoveryLink": "./apis/example/v1/rest",
"discoveryRestUrl": "https://example.appspot.com/_ah/api/discovery/v1/apis/example/v1/rest",
"icons": {
"x16": "http://www.google.com/images/icons/product/search-16.gif",
"x32": "http://www.google.com/images/icons/product/search-32.gif"
},
"id": "example:v1",
"kind": "discovery#directoryItem",
"name": "example",
"preferred": true,
"version": "v1"
}
]
The root discovery document will have an items
member listing the available
APIs and a discoveryLink
for each API. The discoveryLink
provides the schema
for the API. We can download this schema and use it as input to the client
generator.
http --download https://example.appspot.com/_ah/api/discovery/v1/apis/example/v1/rest
generate_library --input=rest.json --language=csharp --output_dir=tmp/csharp
Your C# client library is now ready to use. As of this writing you can generate client libraries in C++, C#, Dart, GWT, Java, PHP and Python.