Designing the American Flights API Spec
Use Anypoint Code Builder to create a REST 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
-
Set up and access the web or desktop IDE.
See Getting Started with Anypoint Code Builder for guidance.
-
Have some familiarity with business groups.
API specifications belong to a business group.
Start American Flights API
Start creating the American Flights API specification:
-
In the activity bar of the IDE, click the (Anypoint Code Builder) icon.
-
From Quick Actions, click Design an API:
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.
-
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 Type
REST API
Anypoint Code Builder supports the REST API type for design.API Specification Language
RAML 1.0
Anypoint Code Builder supports OAS (JSON), OAS (YAML), and RAML. -
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:
-
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.
-
Before starting the configuration, open the Output panel to the Mule DX Server to track the progress of internal processing.
To open the panel:
-
Press Cmd+Shift+u (Mac) or Ctrl+Shift+u (Windows) to open the Output panel.
-
Select Mule DX Server from the drop-down menu in the panel.
For more guidance, see Opening the Output Panel.
-
-
In
american-flights-api.raml
, paste this RAML code for the/flights
endpoint andget
method into the file:#%RAML 1.0 title: American Flights API /flights: get:
-
On the next line directly under
get
, press Ctrl+Space to display all the available options, and select apost
method:#%RAML 1.0 title: American Flights API /flights: get: post:
-
Click the API Console icon to display your specification in the console:
-
Monitor Mule DX Server in the Output panel while the API Console loads.
-
Click your specification file in the editor to display endpoints for the specification file in API Console.
-
Wait for the endpoint icons to render in API Console.
Endpoint and methods in the API Console:
-
-
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.
-
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:
-
View the nested resource in the API Console:
-
Proceed to Adding Examples to the API Spec.