Testing and Deploying an API Backend
Testing an API backend follows the typical App Engine pattern of using the development server to run the web app locally during development and incremental testing, followed by deployment to production when you are ready for real-world testing.
Running and testing API backends locally
To test the backend, you'll use the API Explorer, which is a tool that lets you
test APIs interactively without using a client app. This tool is
automatically run for you when you navigate to your backend API's subdirectory
/_ah/api/explorer
as we'll describe in the instructions below.
To test the API backend locally on the development server:
-
If necessary, specify a different port and address other than the defaults. For example, if you want the app to listen to the local network, you may need to change the address to
0.0.0.0
. For instructions, see Specifying a port for local testing . -
Start the API backend by invoking the development app server. Using Maven, invoke the command from the project's
<app>-ear
subdirectory (not from the<app>-war
):mvn appengine:devserver
Wait til the backend loads; if it loads successfully, this message is displayed:
INFO: Dev App Server is now running.
-
In your browser, visit the URL
http://localhost:8080/_ah/api/explorer
-
Double-click the API you created to display the list of its methods.
-
Click the method you wish to test, fill in any request fields as needed, then click Execute to test the method: the request will be displayed along with the response.
If you want to use
curl
instead of the API Explorer, you can alternatively
test the API backend by sending an test request using
curl
. The following request makes a call to
a sample Board API backend to send a request to our sample tictactoe game:
curl --header "Content-Type: application/json" -X POST -d '{"state": "----X----"}' http://localhost:8888/_ah/api/tictactoe/v1/board
Testing clients against the backend
You can test your client against a backend API running in production App Engine at any time without making any changes. However, if you want to test your client against a backend API running on the local development server, you'll need to make changes as described below:
- For more information on testing JavaScript clients locally, see Testing a JavaScript client against a local development server .
- For more information on testing Android clients locally, see Testing an Android client against a local development server .
Deploying an API backend
When you are satisfied that your API backend works as expected, you can deploy it to App Engine. Deploying an API backend is no different from deploying a regular App Engine app: full instructions for deploying are provided in the deploying and uploading topic.
To deploy: