-
Use the keyboard shortcuts:
-
Mac: Cmd+Shift+p
-
Windows: Ctrl+Shift+p
-
-
In the desktop IDE, select View > Command Palette.
-
In the cloud IDE, click the (menu) icon, and select View > Command Palette.
Implementing the American Flights API Spec
Import your American Flights API specification from Anypoint Exchange. Scaffold the specification into the American Flights project that you are developing, and add the logic to implement an endpoint in the API.
Import and Scaffold Your American Flights API Specification
Import your American Flights API specification from Anypoint Exchange, and scaffold the specification into an interface for your American Flights integration project.
-
In Anypoint Code Builder, open your integration,
american-ws-anypoint-code-builder
.For information about this application, see Integrating American Flights Processes.
-
Open the Command Palette.
Show me how
-
Provide this command:
MuleSoft: Import Asset from Exchange
-
Select Rest API:
-
If prompted, log in to Anypoint Platform, allowing the extension to sign in and open an external web site and to open Visual Studio Code.
-
Type the name of your American Flights API specification, for example:
American Flights API
For information about this specification, see Designing the American Flights API Spec.
-
Wait for the IDE to load a list of matches to the name:
-
When prompted for a version, select the version of the API to import, such as
1.0.0
. -
Select Yes when prompted to scaffold the API dependency.
This step adds the API specification as a dependency in your project’s
pom.xml
file and creates a new configuration XML file, such asamerican-flights-api.xml
: -
Proceed to Tour the Interface File.
Tour the Interface File
Examine the scaffolded flows and error handlers for your interface in the canvas and configuration XML.
-
From the EXPLORER menu, open the configuration file for your interface,
american-flight-api.xml
. -
Use the Flow List panel to navigate through flows:
-
Expand the Flow List panel.
-
Select a flow from the list.
-
Click the flow in the canvas to highlight the flow in the configuration XML.
-
-
In the configuration XML, locate the flows created for the endpoints in your API specification:
-
get:\flights
<flow name="get:\flights:american-flight-api-config"> </flow>
-
post:\flights
<flow name="post:\flights:application\json:american-flight-api-config"> </flow>
-
get:\flights{ID}
<flow name="get:\flights\(ID):application\json:american-flight-api-config"> </flow>
-
-
Notice the automatically generated Error Handler components, for example:
<apikit:router config-ref="american-flights-api-config" /> <error-handler> <on-error-propagate type="APIKIT:BAD_REQUEST"> </on-error-propagate> <on-error-propagate type="APIKIT:NOT_FOUND"> </on-error-propagate> <on-error-propagate type="APIKIT:METHOD_NOT_ALLOWED"> </on-error-propagate> <on-error-propagate type="APIKIT:NOT_ACCEPTABLE"> </on-error-propagate> <on-error-propagate type="APIKIT:UNSUPPORTED_MEDIA_TYPE"> </on-error-propagate> <on-error-propagate type="APIKIT:NOT_IMPLEMENTED"> </on-error-propagate> </error-handler>
-
Proceed to Name Your Interface and Implementation Files.
Name Your Interface and Implementation Files
Provide descriptive names for the interface and implementation files in your American Flights project. The interface receives all incoming requests to your application. The scaffolded flows in the interface validate and route requests. The implementation provides the backend logic for calls to the interface.
-
Rename
american-flight-api-acb.xml
tointerface.xml
by right-clicking the file name, selecting Rename, and providing the new name. -
Rename
american-ws-anypoint-code-builder.xml
toimplementation.xml
. -
Proceed to Configure an Endpoint through the Interface.
Configure an Endpoint through the Interface
To receive HTTP requests through the interface, remove the HTTP listener from implementation.xml
, and in your interface file (interface.xml
), add a Flow Ref component (<flow-ref/>
) to the getFlights
flow in your implementation.
-
Open
implementation.xml
. -
Delete the HTTP /flights listener XML from the configuration XML:
<http:listener path="flights" config-ref="inbound-request" doc:name="HTTP /flights" />
Click for the resulting flow.
<flow name="getFlights"> <db:select doc:name="Query Flights" doc:id="pvuqsc" config-ref="Database_Config" > <db:sql> <![CDATA[Select * FROM american]]> </db:sql> </db:select> <ee:transform doc:name="Transform Message" doc:id="uniqueId" > <ee:message > <ee:set-payload > <![CDATA[ %dw 2.0 output application/json --- payload map ( payload01 , indexOfPayload01 ) -> { ID: payload01.ID, code: (payload01.code1 default "") ++ (payload01.code2 default ""), price: payload01.price default 0, departureDate: payload01.takeOffDate as String default "", origin: payload01.fromAirport default "", destination: payload01.toAirport default "", emptySeats: payload01.seatsAvailable default 0, plane: { "type": payload01.planeType default "", totalSeats: payload01.totalSeats default 0 } } ]]> </ee:set-payload> </ee:message> </ee:transform> </flow>
-
In Anypoint Code Builder, open your
interface.xml
file. -
Locate the
get:\flights:american-flights-api-config
flow:<flow name="get:\flights:american-flights-api-config"> <logger level="INFO" message="get:\flights:american-flights-api-config" /> </flow>
-
Before the
<logger/>
element in the flow, add a Flow Reference component (<flow-ref/>
) that references the flowgetFlights
in the implementation:<flow name="get:\flights:american-flights-api-config"> <flow-ref doc:name="getFlightsRef" name="getFlights"/> <logger level="INFO" message="get:\flights:american-flights-api-config" /> </flow>
-
Optional: Trigger a flow through your interface, and process the request with your implementation.
For guidance, see Triggering Flows in Your Development Environment.
-
Proceed to Debugging the American Flights App.