Contact Us 1-800-596-4880

Designing the American Flights API Spec

logo cloud IDE Cloud IDE

logo desktop IDE Desktop IDE

Open Beta Release: The cloud IDE is in open beta. Any use of Anypoint Code Builder in its beta state is subject to the applicable beta services terms and conditions, available from the IDE.

Use Anypoint Code Builder to create an API specification example called American Flights API. In this API, reuse API fragments from Anypoint Exchange, create data types and response examples, test your API using API Console, and publish the API as an asset to Exchange.

After completing all API specification tasks, implement the specification within an integration. For more information, see Develop the American Flights App.

Before You Begin

Start American Flights API

Start creating the American Flights API specification:

  1. In the activity bar of the IDE, click the (Anypoint Code Builder) icon.

    MuleSoft icon in the VS Code Activity Bar
  2. From Quick Actions, click Design an API:

    Link to Design an API in the MuleSoft panel

    If you receive the error Mule DX API Component was not installed, wait for Mule runtime to load and for background processes to complete. To monitor background processes, see Project Loading Errors.

  3. Configure your API specification project using these values:

    Field Name Field Value

    Project Name

    American Flights API
    Alternatively, provide a similar name of your choice. The name must be unique. The name of the project and specification file is based on the name you provide.

    Project Location

    Your home directory or another directory you create (see Adding Folders to Your Home Directory).

    API Specification Language

    RAML 1.0
    Anypoint Code Builder supports OAS and RAML.

  4. Select Create Project to generate the American Flights API project file: american-flights-api.raml.

    The file name is based on the name you provide for the project:

    Project for American Airlines API
  5. Proceed to Add a RAML Resource and Methods.

Add a RAML Resource and Methods

In American Flights API, start configuring the specification, and try its GET method from the API Console.

  1. Before starting the configuration, open the Output panel to the Mule DX Server to track the progress of internal processing.

    To open the panel:

    1. Press Cmd+Shift+u (Mac) or Ctrl+Shift+u (Windows) to open the Output panel.

    2. Select Mule DX Server from the drop-down menu in the panel.

      For more guidance, see Opening the Output Panel.

  2. In american-flights-api.raml, paste this RAML code for the /flights endpoint and get method into the file:

    #%RAML 1.0
    title: American Flights API
    
    /flights:
      get:
  3. On the next line directly under get, press Ctrl+Space to display all the available options, and select a post method:

    #%RAML 1.0
    title: American Flights API
    
    /flights:
      get:
      post:
  4. Click the API Console icon to display your specification in the console:

    A specification with get and post methods
    1. Monitor Mule DX Server in the Output panel while the API Console loads.

    2. Click your specification file in the editor to display endpoints for the specification file in API Console.

    3. Wait for the endpoint icons to render in API Console.

      Endpoint and methods in the API Console:

      GET and POST methods highlighted in *API Console*
  5. Proceed to Add Query Parameters and Nested Resources.

Add Query Parameters and Nested Resources

Add a nested resource (/{ID}:) to use for getting a flight based on its destination, and specify optional query parameters for the destinations (queryParameters:) as a set of enum values.

  1. Replace your RAML content with this specification:

    #%RAML 1.0
    title: American Flights API
    
    /flights:
      get:
        queryParameters:
          destination:
            required: false
            enum:
              - SFO
              - LAX
              - CLE
      post:
    
      /{ID}:
        get:
  2. View the nested resource in the API Console:

    API Console with nested resource
  3. Proceed to Adding Examples to the API Spec.