---
schema_version: "1"
id: 8b4cdb88c6fb6aae49450ce78df6e61b4cdb886bbde6e2444120945f25f7b0eb
title: Debug the American Flights API
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/anypoint-code-builder/tut-flights-debug-api.md
canonical_url: https://docs.mulesoft.com/anypoint-code-builder/tut-flights-debug-api
source_site: docs.mulesoft.com
content_type: documentation
content_hash: aae81d5cd6116177109740a9d0029f92f3bae15e0249d38a611fe8d5f38aae17
description: MuleSoft Documentation Site
latest: true
---
---
product: Anypoint Code Builder
version: master
---

# Debug the American Flights API

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

After implementing your API flows, validate that the application behaves as expected before writing
automated tests. In this section, you run the project locally and use the debugger to trace request
execution and error routing.

## Run the Application Locally

Before testing your API, start the Mule application locally to verify the implementation works as
designed.

1.  Open the `american-flights-api-main` flow.

2.  Click the **Listener** element.

3.  On the **Connection Config** field, click **Edit Connection**
    (![The Edit Connection icon.](/mulesoft/current/en-us/anypoint-code-builder/_images/icon-gear.png)).

    ![The Listener properties panel with Edit Connection selected next to the Connection Config field](/mulesoft/current/en-us/anypoint-code-builder/_images/tut-flights-listener-config.png)

4.  Verify the values and update them if necessary:

    <table><colgroup><col> <col></colgroup><thead><tr><th>Field Name</th><th>Field Value</th></tr></thead><tbody><tr><td><div><div><p><strong>Host</strong></p></div></div></td><td><div><div><p><code>0.0.0.0</code></p></div></div></td></tr><tr><td><div><div><p><strong>Port</strong></p></div></div></td><td><div><div><p><code>8081</code></p></div></div></td></tr></tbody></table>

5.  Open the Run and Debug panel.

    Show me how

    - Click the ![](/mulesoft/current/en-us/anypoint-code-builder/_images/icon-run-debug.png) (**Run and Debug**) icon in the activity bar.

    - Use the keyboard shortcuts:

      - Mac: Cmd+Shift+d

      - Windows: Ctrl+Shift+d

    - Select **View** > **Run**.

6.  In the top menu, ensure **Run Mule Application** is selected and click **Start Debugging**
    (![The Start Debugging icon.](/mulesoft/current/en-us/anypoint-code-builder/_images/icon-start-debug.png)).

7.  Wait for the application to deploy. You see deployment messages in the **Output** panel.

    When deployment is complete, you see a message similar to:

    ```command
    **********************************************************************
    *            - - + APPLICATION + - -            * - - + STATUS + - -  *
    **********************************************************************
    * american-flights-api-implementation-1.0.0 * DEPLOYED     *
    **********************************************************************
    ```

8.  In your REST client (such as Advanced REST Client), test your API endpoints:

    - Send `GET [http://localhost:8081/api/flights](http://localhost:8081/api/flights)` and verify a
      `200` response with flight data.

    - Send `GET [http://localhost:8081/api/flights/AA123](http://localhost:8081/api/flights/AA123)`
      and verify a `200` response with data for flight with `"ID": 1`.

    - Send `GET [http://localhost:8081/api/flights/123](http://localhost:8081/api/flights/123)` and
      verify a `400` response from your API specification’s path parameter validation.

9.  In Anypoint Code Builder, click **Stop**
    (![The Stop application icon. 2%](/mulesoft/current/en-us/anypoint-code-builder/_images/icon-stop.png)) in the debug bar. == Understand the
    Debugger

The built-in debugger in Anypoint Code Builder helps you understand how your Mule application
processes requests, inspect variable values at runtime, and trace error-handling paths.

Breakpoints pause execution at specific components in your flow, so you can inspect the current
state of the message payload, attributes, and variables. There are two types of breakpoints:

- **Component Breakpoint**: Pauses execution before a specific component executes (such as a
  Transform Message or Database Select operation).

- **Error Breakpoint**: Pauses execution when an error occurs, allowing you to inspect the error
  object.

When the application running in debug mode reaches a component with a breakpoint, execution pauses
and the IDE highlights the current component with a yellow border.

The **Debug** panel opens automatically, showing the current values of Mule variables, message
attributes, payload, and the flow execution path leading to the current breakpoint.

## Set Component Breakpoints

Set breakpoints in your application to pause execution and evaluate values at runtime.

1.  With your application stopped, open the `get:\flights\(flightId):american-flights-api-config`
    flow.

2.  Right-click the **Flight by ID** Database Select operation.

3.  Select **Add Breakpoint** from the context menu.

    A red dot appears on the component, indicating an active breakpoint.

    ![The get:\\flights\\(flightId):american-flights-api-config flow with breakpoints set on the Flight by ID Database Select and Transform Flight components](/mulesoft/current/en-us/anypoint-code-builder/_images/tut-flights-add-breakpoint.png)

4.  Add a breakpoint on the **Transform Flight** component after the database query to inspect the
    payload.

## Start a Debug Session

1.  Click the **Run and Debug** icon in the activity bar.

2.  Ensure **Debug Mule Application** is selected in the dropdown.

    ![The Run and Debug dropdown with Debug Mule Application selected](/mulesoft/current/en-us/anypoint-code-builder/_images/tut-flights-debug-app.png)

3.  Click the **Start Debugging** button (green play icon).

4.  Wait for the application to deploy in debug mode.

## Step Through the Execution and Inspect Variables and Payload

1.  After your application starts running in debug mode, send a GET request from your REST client to
    your local application:

    ```command
    http://localhost:8081/api/flights/AA123
    ```

    The execution pauses at the **Flight by ID** breakpoint.

2.  In the **Variables** section of the Debug panel, expand **Mule Message > Payload**.

    At this point, the message is empty because the query to the database hasn’t executed.

3.  Expand **Mule Message > Attributes** to see HTTP request information:

    - `uriParams.flightId`: The flight ID from the URL.

    - `headers`: HTTP headers.

    - `method`: HTTP method (GET, POST, and so on).

4.  Expand **Variables** to see Mule variables created by Transform Message components:

    - `flightCodeMap`: The flight code mapping.

    - `dbFlightId`: The database ID for the flight.

5.  To evaluate a DataWeave expression, in the Debug panel, locate the **Watch** section.

6.  Click **Add Expression** to add a watch expression.

    ![The Watch section with the Add Expression icon highlighted](/mulesoft/current/en-us/anypoint-code-builder/_images/tut-flights-add-expression.png)

    If the button doesn’t show, collapse and expand the **Watch** section so it shows again.

7.  Enter a DataWeave expression, such as:

    ```dataweave
    attributes.uriParams.flightId
    ```

8.  Press Enter.

    The IDE evaluates the expression and displays the result.

9.  Click **Step Over** (or press F10) to continue the execution.

    ![The Step Over button in the debug toolbar](/mulesoft/current/en-us/anypoint-code-builder/_images/tut-flights-step-over.png)

10. Execution stops at the **Transform Flight** component.

11. Expand **Mule Message > Payload**.

    Notice that now the message contains the results from the database query.

12. Click **Disconnect (SHIFT+F5)** (![The Disconnect icon.](/mulesoft/current/en-us/anypoint-code-builder/_images/icon-stop.png)) to finish
    debugging.

## Debug Error Paths

To understand how your API handles errors, debug the validation and error-handling logic.

1.  Set breakpoints on:

    - The Choice router in `get:\flights\(flightId):american-flights-api-config`.

    - The Raise Error component inside the **When** path.

2.  Start debugging and send an invalid request in your REST client:

    ```command
    GET http://localhost:8081/api/flights/AA999
    ```

    The execution pauses at the Choice router.

3.  In **Variables**, inspect `dbFlightId` (should be `null` because `AA999` isn’t in the mapping).

4.  Click **Step Over** (F10).

    Execution moves to the **When** path and pauses at Raise Error.

5.  Click **Step Over** (F10).

    Execution pauses at the On Error Propagate handler for `VALIDATION:FLIGHT_NOT_FOUND`:

6.  In **Parameters**, verify:

    - `type`: `VALIDATION:FLIGHT_NOT_FOUND`

    - `description`: `"Flight code AA999 not found in our system"`

7.  Click **Continue** (F5) to complete the error response.

Once your application behaves as expected, add automated tests in
[Test the American Flights API with MUnit](https://docs.mulesoft.com/anypoint-code-builder/tut-flights-munit-test-api).

[Validate Input Parameters and Transform Flight Data](https://docs.mulesoft.com/anypoint-code-builder/tut-flights-validate-transform-data)
[Test the American Flights API with MUnit](https://docs.mulesoft.com/anypoint-code-builder/tut-flights-munit-test-api)
