*This page
applies to **Apigee** and **Apigee hybrid**.*


*View [Apigee Edge](https://docs.apigee.com/api-platform/get-started/what-apigee-edge) documentation.*
![](https://fonts.gstatic.com/s/i/googlematerialicons/help/v13/gm_grey-24dp/1x/gm_help_gm_grey_24dp.png)

![](https://docs.cloud.google.com/static/apigee/docs/api-platform/images/ng-saas/chevrons-3-next.png)
**What you'll learn**

In this tutorial, you'll learn to:

- Create an Apigee API proxy from an OpenAPI Specification.
- Call the API proxy using cURL.
- Add a policy to a conditional flow.
- Test the policy invocation using cURL.
You'll learn how to create an Apigee API proxy from an OpenAPI
Specification using the Apigee UI. When you call the API proxy with an
HTTP client, such as cURL, the API proxy sends the request to the Apigee mock target
service.

**About the Open API Initiative**

[![Open API Initiative](https://docs.cloud.google.com/static/apigee/docs/api-platform/images/OpenAPI_Pantone.png)](https://openapis.org)

"The Open API Initiative (OAI) is focused on
creating, evolving and promoting a vendor neutral API Description Format based on the Swagger
Specification." For more information about the Open API Initiative, see [The OpenAPI Specification](https://openapis.org).

An *OpenAPI Specification* uses a standard format to describe a RESTful API.
Written in either JSON or YAML format, an OpenAPI Specification is machine readable, but is
also easy for humans to read and understand. The specification describes such elements of an
API as its base path, paths and verbs, headers, query parameters, operations, content types,
response descriptions, and more. In addition, an OpenAPI Specification is commonly used to
generate API documentation.

**About the Apigee mock target service**

The Apigee mock target service used in this tutorial is hosted at Apigee and returns
simple data. It requires no API key or access token. In fact, you can access it in a web
browser. Try it out by clicking the following:

[http://mocktarget.apigee.net](https://mocktarget.apigee.net)

The target service returns the greeting `Hello, guest!`

For information about the full set of APIs the mock target service supports, see
[Apigee Sample APIs](https://mocktarget.apigee.net/help)

## What you'll need

- **Before you begin, you must complete the steps in** [Overview and prerequisites](https://docs.cloud.google.com/apigee/docs/api-platform/get-started/overview.md.txt).
- An OpenAPI Specification. In this tutorial, you'll use the `mocktarget.yaml` OpenAPI Specification which describes Apigee's mock target service, `http://mocktarget.apigee.net`. For more information, see [apigee/api-platform-samples](https://github.com/apigee/api-platform-samples/tree/master/default-proxies/helloworld/openapi).
- [cURL](https://curl.haxx.se/) installed on your machine to make API calls from the command line; or a web browser.

## Create the API proxy

To create the API proxy from an OpenAPI Specification:

1. In the Google Cloud console, go to the **Apigee \> Proxy development \> API proxies** page.

   [Go to API proxies](https://console.cloud.google.com/apigee/proxies)
2. In the **API Proxies** pane, click **+ Create**.
3. In the **Create a proxy** pane, under **Proxy template** \> **OpenAPI spec template** , select **Reverse proxy (Most common)**.
4. Navigate to the following URL in your web browser:

   ```
   https://raw.githubusercontent.com/apigee/api-platform-samples/master/default-proxies/helloworld/openapi/mocktarget3.0.yaml
   ```
5. Right-click on the displayed code and select **Save As**.
6. Click **Save** to save the `mocktarget3.0.yaml` at the desired location.
7. In the **OpenAPI specs** field, click the **Browse** button.
8. Navigate to the `mocktarget3.0.yaml` file and click **Open**.
9. Click **Next**.
10. The **Proxy details** step of the **Create Proxy** wizard automatically populates its fields with values extracted directly from the OpenAPI Specification.
11. The following table describes the default values that are pre-populated using the OpenAPI Specification:

| Field | Description | Default |
|---|---|---|
| **Proxy name** | Name of the API proxy. For example: `Mock-Target-API`. | `title` property from the OpenAPI Specification with spaces replaced by dashes |
| **Base path** | Path component that uniquely identifies this API proxy within the organization. The public-facing URL of this API proxy is comprised of your external or internal domain name and this base path. For example: `http://apitest.acme.com/mock-target-api` | **Name** field content converted to all lower case |
| **Description** | Description of the API proxy. | `description` property from the OpenAPI Specification |
| **Target (Existing API)** | Target URL invoked on behalf of this API proxy. Any URL that is accessible over the open Internet can be used. For example: `http://mocktarget.apigee.net` | `servers` property from the OpenAPI Specification |

12. The following provides an excerpt from the OpenAPI Specification showing the properties that are used to pre-populate the fields.

```
      openapi: 3.0.0
      info:
        description: OpenAPI Specification for the Apigee mock target service endpoint.
        version: 1.0.0
        title: Mock Target API
      paths:
        /:
          get:
            summary: View personalized greeting
            operationId: View a personalized greeting
            description: View a personalized greeting for the specified or guest user.
            parameters:
              - name: user
                in: query
                description: Your user name.
                required: false
                schema:
                  type: string
            responses:
              "200":
                description: Success
      ...
      servers:
        - url: http://mocktarget.apigee.net
        - url: https://mocktarget.apigee.net
      ...
      
```
13. In the **Proxy details** step, edit the **Description** field as follows:

    ```
    API proxy for the Apigee mock target service endpoint.
    ```
14. Click **Next**.
15. In the **Flows** step, make sure all operations are selected.

    > [!IMPORTANT]
    > **Tip:** Conditional flows are generated automatically from the operations that are defined within the `paths` object in the OpenAPI Specification. Conditional flows tell Apigee, "When you see this, perform this logic." For example, when an API call is a `GET` on the `/xml` resource (the condition), transform the response to JSON (through a policy attached to the conditional flow). Only one flow executes per transaction---the first flow whose condition evaluates to true.

16. Click **Next**.
17. In the **Deploy** step, select one or more environments, and click **OK**.
18. Click **Create**.

> [!TIP]
> **Congratulations!** You've created an API proxy from an OpenAPI Specification. Next you'll test it to see how it works.

## Test the API proxy

You can test your `Mock-Target-API` API using cURL or a web browser.

```
curl -v YOUR_ENV_GROUP_HOSTNAME/myproxy
```

where `YOUR_ENV_GROUP_HOSTNAME` is your environment group hostname. See
[Find your environment group hostname](https://docs.cloud.google.com/apigee/docs/api-platform/get-started/test-proxy.md.txt#find-your-environment-group-hostname).


For example:

```
curl -v -k https://apitest.acme.com/myproxy
```

**Response**

You should see the following response:

```
Hello, Guest!
```

> [!TIP]
> **Way to go!** You've built a simple API proxy from an OpenAPI Specification and tested it.

## Add an XML to JSON policy

Next, you'll add the XML to JSON policy to the **View XML Response**
conditional flow that was generated automatically when you created the API proxy from the
OpenAPI Specification. The policy will convert the target's XML response to a JSON
response.

First, call the API so that you can compare the results with those received after you add
the policy. In a terminal window execute the following cURL command. You're calling the
target service's `/xml` resource, which natively returns a simple block of XML.

```
curl -v https://YOUR_ENV_GROUP_HOSTNAME/mock-target-api/xml
```

where `YOUR ENV_GROUP_HOSTNAME` is the environment group hostname. See
[Find the environment group hostname](https://docs.cloud.google.com/apigee/docs/api-platform/get-started/test-proxy.md.txt#find-the-environment-group-hostname).

**Response**

You should see the following response:

```
<root>
  <city>San Jose</city>
  <firstName>John</firstName>
  <lastName>Doe</lastName>
  <state>CA</state>
</root>
```

Now let's do something that converts the XML response to JSON. Add the XML to JSON policy
to the View XML Response conditional flow in the API proxy.

1. Click the **Develop** tab in the **Mock-Target-API Overview** page in the Apigee UI.

2. ![Select View XML Response](https://docs.cloud.google.com/static/apigee/docs/api-platform/images/view-xml-response-policy.png)
3. In the left-hand pane, under **Proxy Endpoints \> default** , click the **View
   XML Response** conditional flow.
4. In the left-hand pane, click the **+** button in the **Policies** row.
5. In the **Create policy** dialog, click in the **Select policy type** field,
   scroll down to **Mediation** , and select **XMLToJSON** .
   Keep the default values for **Display Name** and **Name**.

6. Click **Create** to create the policy.
7. Click the **+** button next to the **View XML response** flow in the
   **Response**.

   ![Select +Step](https://docs.cloud.google.com/static/apigee/docs/api-platform/images/view-xml-response-add-step.png)
8. In the **Add Policy Step** dialog, click in the **Select existing policy** field and select **XML to JSON-1**.
9. Click **Add**. The XML to JSON policy is applied to the response.

   ![XML to JSON policy in flow](https://docs.cloud.google.com/static/apigee/docs/api-platform/images/xml-to-json-in-flow.png)

   To view the code for the **View XML Response** conditional flow, click
   **Switch To Code Editor**.
10. Click **Save**.

Now that you've added the policy, call the API again using cURL. Notice that you're still
calling the same `/xml` resource. The target service still returns its block of
XML, but now the policy in the API proxy will convert the response to JSON. Make this
call:

```
curl -v https://YOUR_ENV_GROUP_HOSTNAME/mock-target-api/xml
```

where `YOUR ENV_GROUP_HOSTNAME` is the environment group hostname. See
[Find the environment group hostname](https://docs.cloud.google.com/apigee/docs/api-platform/get-started/test-proxy.md.txt#find-the-environment-group-hostname).

Note that the XML response is converted to JSON:

```
{"root":{"city":"San Jose","firstName":"John","lastName":"Doe","state":"CA"}}
```

> [!TIP]
> **Congratulations!** You have successfully tested the execution of a policy added to a conditional flow.