1.
Import and test the backend OpenAPI
specification
Import the backend OpenAPI specification
1. In a different browser tab, open the Apigee console.
2. On the left navigation menu, click D
evelop > Specs.
3. To create a new spec, on the +
Spec menu, click Import URL.
Specify the following:
Property Value
Import name retail-v1
Import URL [Link]
4. Click Import.
5. Click on the specification name, r etail-v1.
When the specification editor opens, the YAML OpenAPI specification is on
the left, and the live documentation is on the right:
Changes made to the YAML specification on the left are immediately
reflected in the documentation on the right.
Test the backend OpenAPI specification
1. In the live documentation, click on the GET /categories box to expand the
panel.
2. Click Try it out, and then click E
xecute.
You should see a successful response.
2. Generate the API proxy
In this task, you use the OpenAPI specification to generate an API proxy.
Generate an API proxy using the OpenAPI specification
1. On the left navigation menu, click D
evelop > API Proxies.
2. To start the proxy wizard, click +
Proxy.
3. Click Use OpenAPI Spec in the R
everse proxy box.
4. Select the r etail-v1 specification, and then click Select.
5. Specify the following:
Property Value
Name retail-v1
Base path /retail/v1
Description My retail API
Leave the Target unchanged.
6. Click Next.
7. Leave the Common Policies settings at their defaults. Click N
ext.
8. Operations that were found in the OpenAPI specification are listed.
Confirm that all operations are selected, and click N
ext.
9. The secure virtual host should be selected, and the default virtual host
should not be selected. Click Next.
10. On the Summary page, select the test environment, and then click
Create and deploy.
Your proxy will be generated and deployed.
11. When deployment is complete, click E
dit proxy.
Explore and trace the API proxy
1. Click the D
evelop tab. This tab is used to edit the proxy that has been
generated. Conditional flows have been created for each of the operations
in the OpenAPI specification. These conditional flows appear in the proxy
endpoint in the Navigator on the left. When you click a conditional flow, it
appears in the Code pane on the right.
You will update these conditional flows in later labs.
2. Click the T
race tab.
3. Deployment to Trace should show the test environment. Click S
tart Trace
Session.
4. To send a "get categories" request to your proxy, add /categoriesto the
URL in the S
end Requests pane.
Your URL should look similar to:
[Link]
Instead of myorg-eval, your URL should include your org name, which can
be found under your name in the upper left corner of the Apigee console.
5. Click Send.
A transaction for this request should appear in the Transactions pane on
the left. When a transaction is selected, you'll see a trace of the request
and response through Apigee. You should see a 2
00 Status code if your
backend URL was correctly set, and you added / categories to the end of
the Send Requests URL.
6. Click on the last circle as shown in the screenshot below. This shows the
response that is being returned to the client.
The Send Requests pane is an easy way to create a GET request for your
API proxy. However, you cannot add headers, change the verb in the
request, or send a payload. You will need a REST client for later labs.
The Phase Details pane in your trace may look different from the
screenshot, depending on the settings in the View Options pane in the lower
left corner. The screenshots typically show the contents with the
"Automatically Compare Selected Phase" box cleared. If you want your trace
to more closely match screenshots in the labs, clear the "Automatically
Compare Selected Phase" checkbox.
3. Modify the OpenAPI specification to
reference your proxy
In this task, you modify the OpenAPI specification to reference your API proxy
instead of the backend service.
Modify the OpenAPI specification
1. Keep the trace session open. In another tab, open the A
pigee console.
2. On the left navigation menu, click D
evelop > Specs.
3. Click on the r etail-v1 specification.
4. Change the first 15 lines of the OpenAPI specification to look something
like this:
openapi:
"3.0.0"
info:
version:
0.0
.1
title:
RetailAPI v1
description: R
etailAPI
contact:
name: Y
our
Name
email: youremail@[Link]
url: https:
//[Link]
license:
name: MIT
url: https:
//[Link]/licenses/MIT
servers:
- url:
"[Link]
description:
RetailAPI v1
5. You must change the server URL to use your organization. Replace
YOURORG with your organization name. Your org name typically ends with
-eval. The URL should end with /retail/v1.
If you have any problems, you can use the URL in the Send Requests pane
of the trace tool. That URL, after you remove any resource like / categories,
should match this URL.
6. You can optionally change the description and contact information.
7. Click Save to save the proxy.
Test the updated OpenAPI specification
1. Click Start Trace Session in the trace tab. If trace is already running, and
the button is red, click the button to stop the trace, and click again to start
the trace session.
2. On the right side of the Spec page, click the GET /categories box, and try
the call by clicking Try it out and Execute. You should see the call in the
trace tool.
Click on the first circle in the trace to see the request. You may see
headers that were automatically added by the browser, such as Origin,
User-Agent, and Referer.
If you receive a "TypeError: Failed to fetch" error when sending from the
spec, your organization name might not have been specified correctly in the
OpenAPI spec. Confirm the change you made to the first 15 lines of the
OpenAPI spec, and confirm that your [Link] includes "/retail/v1" and
your organization name, which includes "-eval" in most cases.