Generating Client Libraries
- Generating a client library for Android using Maven
- Generating a client library for Android using endpoints.sh
- Generating a discovery doc for iOS using Maven
- Generating a discovery doc for iOS using endpoints.sh
In order for an Android client to access a backend API, the client must use a Java client library generated from the backend API.
To generate a client library from your backend API, you must have already annotated the backend API code. (See the backend API tutorial for more information. The following instructions assume that you have already finished annotating your backend API.
Generating a client library for Android using Maven
If you created your backend API in a Maven project using the App Engine Maven artifacts as described in the backend API tutorial , you generate the client library as follows:
-
Invoke the following command in the directory containing your project
pom.xml
file:mvn appengine:endpoints_get_client_lib
-
Locate the generated client library source directory and files, which are inside your project root directory at this subdirectory location:
/target/endpoints-client-libs/<yourProjectName>
and change directory to this location. -
Invoke Maven to build the client library:
mvn install
-
This builds the required class files and creates the JAR file you need to add to your client project. The JAR file is located inside your current directory at this subdirectory location:
/target/<yourProjectVersion>.<versionString>-rc-SNAPSHOT.jar
-
Add the client library JAR to the Android app as described in Using Endpoints in an Android Client .
Generating a client library for Android using
endpoints.sh
If don't use Maven, you can generate the client libray using the
endpoints.sh
command line tool:
-
Generate the library following the instructions provided in Using the Endpoints Command Line Tool .
-
Remember to repeat the client library generation when you modify the backend API.
-
Add the client library to the Android app as described in Using Endpoints in an Android Client .
Generating a discovery doc for iOS using Maven
To generate the discovery doc for iOS using Maven:
-
Invoke the following command in the directory containing your project
pom.xml
file:mvn appengine:endpoints_get_discovery_doc
-
Note the location of the generated discovery doc. The console will display a message similar to the following:
API Discovery Document written to /<your-path>/<your-projectdir>/target/generated-sources/appengine-endpoints/WEB-INF/helloworld-v1-rpc.discovery
Supply the generated discovery doc to the OS X library generator .
Generating a discovery doc for iOS using
endpoints.sh
For iOS, you need to generate the discovery document for RPC. To generate the discovery doc using the command line tool:
-
Change directory to the parent directory of your project's
/war
directory. Alternatively, use the--war
option to specify the location ofwar
. -
Invoke the Endpoints command line tool similar to the following:
appengine-sdk/bin/endpoints.sh get-discovery-doc --format=rpc \ com.google.devrel.samples.ttt.spi.BoardV1
where the format is set explicitly to
rpc
(since the commmand line tool default is REST), and where you replacecom.google.devrel.samples.ttt.spi.BoardV1
with your own API class. (If your API is implemented across several classes, list each class separated by a space.) -
When successful, the tool displays a message similar to:
INFO: Successfully processed ./war/WEB-INF/appengine-web.xml API Discovery Document written to ./tictactoe-v1-rest.discovery
The discovery document is written to the current directory unless you specify some other output directory using the
output
option .
Supply the generated discovery doc to the OS X library generator .