APStart Studentmanual
APStart Studentmanual
APStart Studentmanual
Anypoint Platform
Student Manual
1
Table of Contents
INTRODUCING THE COURSE ................................................................................................ 3
Walkthrough: Set up your computer for class ................................................................................................. 4
2
Introducing the course
3
Walkthrough: Set up your computer for class
In this walkthrough, you make sure your computer is set up correctly, so you can complete the class exercises.
You will:
Download the course files from the MuleSoft Training Learning Management System.
Make sure Anypoint Studio starts successfully.
Install Advanced REST client (if you did not already).
Make sure you have an active Anypoint Platform account.
3. Log in to your MuleSoft training account using the email that was used to register you for class.
Note: If you have never logged in before and do not have a password, click the Forgot your password
link, follow the instructions to obtain a password, and then log in.
4. On the Dashboard page, select Instructor-led under Enrollments then locate the card for your class.
4
5. Click the course name to see the course overview page then locate the class details on the right
side of the page.
6. Click the Resources tab then locate the list of course materials on the right side of the page.
5
7. Click the student files link to download the files.
8. Click the student manual link to download the manual.
9. Click the student slides link to download the slides.
10. On your computer, locate the student files ZIP and expand it.
11. Open the course snippets.txt file.
Note: Keep this file open. You will copy and paste text from it during class.
Note: If you do not have Anypoint Studio, you can download it from
https://www.mulesoft.com/lp/dl/studio. Upon starting Anypoint Studio, users on Windows may get a
popup asking to allow Windows Defender Firewall access for OpenJDK; access should be allowed.
13. In the Workspace Launcher dialog box, look at the location of the default workspace; change the
workspace location if you want.
14. Click OK to select the workspace; Anypoint Studio should open.
Note: If you cannot successfully start Anypoint Studio, make sure that you have enough available
memory (at least 8GB available) to run Anypoint Studio.
6
15. If you get a new features page, click the Continue to Studio button to close it.
16. If you get an Updates Available popup in the lower-right corner of the application, click it and install
the available updates.
Note: If you do not have Advanced REST Client (or another REST API client) installed, download it now
from https://install.advancedrestclient.com/ and install it.
7
18. Leave Advanced REST client open; you will use it throughout class.
Note: If you do not have an account, sign up for a free, 30-day trial account now. Also, if you get
prompted here or in other parts of the course to enable multi-factor authentication, select Not Now.
20. Click the menu button located in the upper-left in the main menu bar.
Note: This will be called the main menu from now on.
8
22. In the left-side navigation, click the Runtime Manager link under Subscription.
23. Check your subscription level and if it is a trial account, make sure it is not expired.
Note: If your trial is expired or will expire during class, sign out and then sign up for a new trial account
now.
9
Module 1: Introducing
application networks and API-led
connectivity
10
Walkthrough 1-1: Explore an API directory and an API
portal
In this walkthrough, you locate and explore documentation about APIs. You will:
11
Explore the API reference for the Vimeo API
3. Enter vimeo in the search text field then press Enter/Return.
12
5. In the Vimeo Version History section, select the Vimeo REST API.
6. In the Specs section, click the API Portal / Home Page link.
7. In the new browser tab that opens, click API Reference in the left-side navigation.
13
8. Review the API Reference for information about endpoints, HTTP methods and parameters.
14
12. Return to a browser window and navigate to that URL:
https://anypoint.mulesoft.com/exchange/portals/muletraining/.
15
18. Review the information about the GET method; you should see there is an optional query
parameter called destination.
16
19. Scroll down and review the Headers and Responses sections.
17
Walkthrough 1-2: Make calls to an API
In this walkthrough, you make calls to a RESTful API. You will:
Use Advanced REST Client to make calls to an unsecured API (an implementation).
Make GET, DELETE, POST, and PUT calls.
Use Advanced REST Client to make calls to a secured API (an API proxy).
Use the API console in an API portal to make calls to a managed API using a mocking service.
Use the API console to make calls to an API proxy endpoint.
Note: This is the URL for the API implementation, not the managed API proxy. The -ws stands for web
service.
5. Return to Advanced REST Client and paste the URL in the text box that says Request URL,
replacing any existing content.
18
6. Click the Send the request button; you should get a response.
7. Locate the return HTTP status code of 200.
8. Review the response body containing flights to SFO, LAX, and CLE.
10. Click the Open parameters editor icon (the pencil) to the right of the URL.
11. In the query parameters editor area that appears, click the Add button.
19
12. Set the parameter name to destination and the parameter value to CLE then click Close.
13. Click the Send the request button; you should get just flights to CLE returned.
14. Edit the query parameters again, click the Remove this parameter button next to the parameter to
delete it, then click Close.
15. Change the request URL to add a URI parameter to retrieve the flight with an ID of 3:
http://training4-american-ws.cloudhub.io/api/flights/3.
16. Click the send button; you should see only the flight with that ID returned.
20
18. Click the send button; you should see a 200 response with the message Flight deleted (but not
really).
Note: The database is not actually modified so that its data integrity can be retained for class.
21
23. Click the Add button in the header area.
24. Select Content-Type in the resultant Header name drop-down menu.
25. Type app in the Header value field then select application/json.
29. Click the send button; you should see a 201 Created response with the message Flight added (but
not really).
22
30. Return to the request body and remove the plane field and value from the request body.
31. Remove the comma after the emptySeats key/value pair.
32. Send the request; the message should still post successfully.
33. In the request body, remove the emptySeats key/value pair.
34. Delete the comma after the destination key/value pair.
35. Send the request; you should see a 400 Bad Request response with the message Bad request.
23
38. Click the send button; you should get a 400 Bad Request.
39. In the request body field, press Cmd+Z or Ctrl+Z until the emptySeats field is added back.
40. Send the request; you should get a 200 OK response with the message Flight updated (but not
really).
Note: The -ws in the URL has been changed to -api and the /api removed.
44. Click the send button; you should get a 401 Unauthorized response with the message Invalid client
id or secret.
45. Return to the course snippets.txt file and copy the value for the American Flights API client_id.
46. Return to Advanced REST Client and add a header called client_id.
47. Set client_id to the value you copied from the snippets.txt file.
48. Return to the course snippets.txt file and copy the value for the American Flights API client_secret.
49. Return to Advanced REST Client and add a second header called client_secret.
24
50. Set client_secret to the value you copied from the snippets.txt file.
Note: The client credentials in the snippets file may be different than what is shown here; the values in
the snippets file differ for instructor-led and self-study training classes.
51. Click the send button; you should get data for flight 3 again.
52. Click the send button several more times; you should get a 429 Too Many Requests response with
the message Quota has been exceeded.
Note: For the self-study training class, the API service level agreement (SLA) for the application with
your client ID and secret has been set to allow three API calls per minute while, for the instructor-led
class, the SLA allows for a higher number to accommodate shared use.
25
Use the API console in the API portal to make requests to the API using a mocking
service
53. Return to the browser window with the American Flights API portal at
https://anypoint.mulesoft.com/exchange/portals/muletraining.
54. In the left-side navigation click the GET method for /flights.
55. Review the Headers and Responses sections.
56. In the Responses section, look at the output example.
57. In the API console located on the right side of the page, make sure the Mocking Service endpoint is
selected.
26
58. Look at the endpoint URL that is displayed.
27
64. Click Send; you should get a 401 Unauthorized response.
65. Copy and paste the client_id and client_secret values from the course snippets.txt file.
66. Click Send; you should get a 200 OK response with only flights to LAX.
28
Module 2: Introducing Anypoint
Platform
Describe the benefits of Anypoint Platform and MuleSoft’s approach to be successful with it.
Describe the role of each component in building application networks.
Navigate Anypoint Platform.
Locate APIs and other assets needed to build integrations and APIs in Anypoint Exchange.
29
Walkthrough 2-1: Explore Anypoint Platform and Anypoint
Exchange
In this walkthrough, you get familiar Anypoint Platform. You will:
Note: If you closed the browser window or logged out, return to https://anypoint.mulesoft.com and log
in.
2. Click the menu button located in the upper-left in the main menu bar.
3. In the menu that appears, select Anypoint Platform; this will return you to the home page.
Note: This will be called the main menu from now on.
30
Explore Anypoint Platform
4. In the main menu, select Access Management.
5. In the left-side navigation, select Users.
6. In the left-side navigation, select Environments.
31
12. In the main menu, select API Manager.
15. In the left-side navigation, select the name of your organization above Provided by MuleSoft
(Training in the screenshots); you should now see only the content in your private Exchange, which
is currently empty.
32
17. In the types menu, select Connectors.
33
Browse REST APIs in Anypoint Exchange
25. In the types menu, select REST APIs.
26. Browse the APIs.
Discover and review the API portal for the Training: American Flights API
27. Click Try the new search and examine the new search features available in Exchange.
34
28. Click Cancel.
Note: For this course we will use the original Exchange search experience.
31. In the left-side navigation, expand and review the list of available resources.
32. Click the GET link for the /flights resource.
35
33. On the GET /flights page, review the information for the optional destination query parameter; you
should see the API is similar to the one you explored in the public MuleSoft Training portal.
Use the API console to make calls to the Training: American Flights API
34. In the API console, review the options for the instances you can test.
36
37. In the Headers section, enter any values for client_id and client_secret.
38. Click Send; you should get the two example flights.
39. Change the API instance from Mocking Service to Rate limiting SLA based policy.
40. Select a destination in the drop-down menu.
41. In the Headers section, copy and paste the client_id and client_secret values from the course
snippets.txt file
42. Click Send again; you should get results from the actual API implementation for the destination you
selected.
37
Module 3: Designing APIs
38
Walkthrough 3-1: Use API Designer to define an API with
RAML
In this walkthrough, you create an API definition with RAML using API Designer. You will:
3. In the New API Specification dialog box, set the project name to American Flights API.
39
4. Ensure I'm comfortable designing it on my own is selected and click Create API; API Designer
should open.
5. Review the three sections of API Designer: the file browser, the editor, and the API console.
40
View the API console
8. Look at the API console on the right side of the window; you should see summary information for
the API.
Note: If you do not see the API console, click the Documentation icon located in the right column.
Note: If you don’t see the API Designer shelf, it is either minimized or there is an error in your code. To
check if it is minimized, go to the bottom of the web browser window and look for an arrow. If you see
the arrow, click it to display the shelf.
10. Indent by pressing the Tab key; the contents in the API Designer shelf should change.
41
13. In the editor, backspace so you are indented the same amount as the get method.
14. Click the post method in the shelf.
15. Look at the API console; you should see GET and POST methods for the flights resource.
/{ID}:
42
Add an optional query parameter
21. In the editor, indent under the /flights get method (not the /flights/{ID} get method).
22. In the shelf, click the queryParameters parameter.
23. Add a key named destination.
24. Indent under the destination query parameter and look at the possible parameters in the shelf.
25. In the shelf, click the required parameter.
26. In the shelf, click false.
27. Go to a new line of code; you should be at the same indent level as required.
28. In the shelf, click the enum parameter.
29. Set enum to a set of values including SFO, LAX, and CLE.
43
Walkthrough 3-2: Use the mocking service to test an API
In this walkthrough, you test the API using the Anypoint Platform mocking service. You will:
Starting file
If you did not complete the previous walkthrough, you can get a starting file here. This file is also located in the
solutions folder of the student files ZIP located in the Course Resources.
44
4. Click the Try it button for the flights GET method then click the Send button; you should get a 200
status code and an empty response.
5. In the destination drop-down menu, select SFO and click Send; you should get the same response.
45
7. Click the GET method for the /{ID} nested resource.
8. Click Try it; you should see a message that the Request URL is invalid.
46
Test the /flights:post resource
12. Use the menu button located in the upper-left of the API console to return to the resource list.
13. Click the POST method.
14. Click the Try it button then click the Send button.
15. Look at the response; you should get the same generic 200 status code response.
47
17. Locate the Make Public slider under Service Settings.
48
22. Return to Advanced REST Client, paste the copied link and append it with /flights.
23. Add a header called Accept with a value of application/json using the header drop-down menus.
24. Make sure the method is set to GET and click Send; you should get a 200 status code and an
empty response.
49
Walkthrough 3-3: Add request and response details
In this walkthrough, you add information about each of the methods to the API specification. You will:
Starting file
If you did not complete walkthrough 3.1, you can get a starting file here. This file is also located in the solutions
folder of the student files ZIP located in the Course Resources.
50
3. Click the Fragments Add button.
4. In the API Specification Fragments dialog box, select the Training: American Flight Data Type and
the Training: American Flights Example.
51
7. Click the Files button (above the Dependencies button).
8. Expand the exchange_modules section until you see AmericanFlightDataType.raml.
9. Click AmericanFlightDataType.raml and review the code.
10. In the file browser, click the options menu button next to AmericanFlightDataType.raml and select
Copy path.
Note: You can also add the path by navigating through the exchange_modules folder in the shelf.
52
Specify the /flights:get method to return an array of AmericanFlight objects
15. Go to a new line of code at the end of the /flights get method and indent to the same level as
queryParameters.
16. In the shelf, click responses > 200 > body > application/json > type > AmericanFlight.
53
19. In the file browser, click the options menu next to AmericanFlightsExample.raml and select Copy
path.
20. Return to american-flights-api.raml.
21. In the editor, go to a new line after the type declaration in the /flights:get 200 response (at the same
indentation as type).
22. In the shelf, click examples.
23. Add a key called output.
24. Add the !include keyword and then paste the path you copied.
Note: You can also add the path by navigating through the exchange_modules folder in the shelf.
54
27. In the response information, ensure you see the example array of AmericanFlight objects.
28. Click the Try it button and click Send; you should now see the example response with two flights.
55
Define an example response for the /{ID}:get method in a new folder
31. In the file browser, click the add button and select New folder.
32. In the Add new folder dialog box, set the name to examples and click Create.
33. In the settings drop-down menu in the upper-right corner, select Import.
34. In the Import file(s) dialog box, leave File or ZIP selected and click the Choose file button.
35. Navigate to your student files and select the AmericanFlightExample.raml file in the
resources/examples folder and click Open.
36. In the Import file(s) dialog box, click Import.
37. In the file browser, click AmericanFlightExample.raml and review the code.
38. Drag AmericanFlightExample.raml into the examples folder.
56
Add an example response for the /{ID}:get method
39. Return to american-flights-api.raml.
40. In the editor, go to a new line after the type declaration in {ID}:/get (at the same indentation).
41. In the shelf, click examples.
42. Add a key called output.
43. Add an include statement and include the example in examples/AmericanFlightExample.raml.
45. In the response information, ensure you see the example AmericanFlightExample data.
57
46. Click the Try it button, enter an ID, and click Send; you should now see the example flight data
returned.
58
54. Delete the line of code containing the ID.
59
62. Indented under example, add a message property equal to the string: Flight added (but not really).
60
65. Click the Try it button; in the Body section you should see the example request body.
66. Click the Send button; you should now get a 201 response with the example message.
61
68. Click Send again; you should get a 400 Bad Request response and a message that the emptySeats
key is required.
62
Walkthrough 3-4: Add an API to Anypoint Exchange
In this walkthrough, you make an API discoverable by adding it to Anypoint Exchange. You will:
Starting file
If you did not complete the previous walkthrough, you can get a starting file here. This file is also located in the
solutions folder of the student files ZIP located in the Course Resources.
2. In the Publishing to Exchange dialog box, ensure the following values are set:
63
Locate your API in Anypoint Exchange
5. In the file browser, click the Exchange button.
6. Click the Open in Exchange link; the auto-generated portal for your American Flights API opens in a
new browser tab.
7. Select the Exchange link near the upper-left corner of the page; you should see the asset listing for
your API.
8. In the types drop-down menu, select REST APIs; you should still see your API.
64
9. In the left-side navigation, select Provided by MuleSoft; you should not find your American Flights
API in the public Exchange (just the Training: American Flights API).
10. In the left-side navigation, select the name of your organization (Training in the screenshots); you
should see your American Flights API in your private Exchange.
65
13. Locate the API version (v1) and minor version (1.0.x) near the upper-right corner of the page.
66
19. Select AmericanFlight and review the information.
67
22. Click Send; you should get a 200 response and the example data displayed – just as you did in the
API console in API Designer.
25. Return to the course snippets.txt file and copy the text for the American Flights API description text.
26. Return to the editor in Anypoint Exchange and paste the content.
68
27. Select the words american table and click the strong button (the B).
28. Select the words training database and click the emphasis button (the I).
29. Select the words Supported operations and select Heading 4 from the heading drop-down menu
(the H).
30. Select Get all flights and click the bulleted list button.
31. Repeat for the other operations.
69
32. Select the Visual tab in the editor toolbar and view the rendered markdown.
33. Click the Save button; you should now see buttons to discard, view, edit, or publish the draft.
34. Click the Publish button; you should now see the new information about the API in the API portal.
70
Modify the API and publish the new version to Exchange
36. Return to the browswer tab with your American Flights API in API Designer.
37. Return to the course snippets.txt file and copy the American Flights API - /{ID} DELETE method.
38. Return to american-flights-api.raml and paste the code after the {ID}/get method.
39. Fix the indentation if necessary.
40. Review the code.
71
43. Wait for the API to publish then in the resultant dialog box, click Close.
44. Navigate to the portal for your American Flights API using the Exchange button in the file browser.
45. Click the Manage versions button.
46. In the Patch versions for 1.0 dialog box, you should see both asset versions of the API listed with
an associated API instance using the mocking service for the latest version.
72
49. Add the new delete a flight operation.
73
Walkthrough 3-5: Share an API
In this walkthrough, you share an API with both internal and external developers to locate, learn about, and try
out the API. You will:
Starting file
If you did not complete the previous walkthrough, you can get a starting file here. This file is also located in the
solutions folder of the student files ZIP located in the Course Resources.
74
3. In the Share dialog box, you should see that you are an Admin for this API.
4. Click Cancel.
5. In the left-side navigation, click Assets list.
6. In the left-side navigation, select the name of your organization if necessary.
7. Click your American Flights API.
Note: This is how users you share the API with will find the API.
75
Create a public API portal
8. Click the Share button for the API again.
9. In the Share dialog box, click the Public tab.
76
14. Review the public portal that opens in a new browser tab.
15. Look at the URL for the public portal.
16. Click your American Flights API and review the auto-generated public API portal.
17. In the left-side navigation, click the GET method for the flights resource.
18. Review the response information.
77
19. In the API console, click Send; you should get a 200 response with example flights returned from
the mocking service.
78
22. In the Title field, change the text to Welcome to your MuleSoft Training portal!
79
Explore the public portal as an external developer
32. In the browser, copy the URL for the public portal.
33. Open a new private or incognito window in your browser.
34. Navigate to the portal URL you copied; you should see the public portal (without the customize
button).
Note: As an anonymous user, you can make calls to an API instance that uses the mocking service but
not managed APIs.
80
Module 4: Building APIs
81
Walkthrough 4-1: Create a Mule application with Anypoint
Studio
In this walkthrough, you build a Mule application. You will:
82
3. In the New Mule Project dialog box, set the Project Name to training4-american-ws.
4. Ensure the Runtime is set to the latest version of Mule.
5. Click Finish.
7. Drag the Listener operation from the Mule Palette to the canvas.
83
8. In the Listener properties view that opens at the bottom of the window, click the Add button next to
connector configuration.
9. In the Global Element Properties dialog box, verify the following default values are present.
Host: 0.0.0.0
Port: 8081
84
11. In the Listener properties view, set the path to /flights.
15. Review the information in the Global Element Properties dialog box and click Cancel.
16. Select the Message Flow tab to return to the canvas.
Display data
17. In the Mule Palette, select Core.
85
18. Scroll down in the right side of the Mule Palette and locate the Transformers section.
19. Drag the Set Payload transformer from the Mule Palette into the process section of the flow.
86
22. Select the Configuration XML tab at the bottom of the canvas and examine the corresponding XML.
Comment a component
24. Right-click the Set Payload transformer and select Toggle Comment.
87
25. Select the Configuration XML tab at the bottom of the canvas and examine the changes to the XML.
Note: If you get a dialog asking to accept incoming network connections, click Allow.
88
30. Watch the Console view; it should display information letting you know that both the Mule runtime
and the training4-american-ws application started.
89
Walkthrough 4-2: Connect to data (MySQL database)
In this walkthrough, you connect to a database and retrieve data from a table that contains flight information.
You will:
Starting file
If you did not complete the previous walkthrough, you can get a starting file here. This file is also located in the
solutions folder of the student files ZIP located in the Course Resources. See here for steps on importing a
starting file deployable jar archive into Studio.
Note: The database information you see may be different than what is shown here; the values in the
snippets file differ for instructor-led and self-study training classes.
90
Add a Database connector endpoint
2. Return to Anypoint Studio.
3. Right-click the Set Payload message processor and select Delete.
4. In the Mule Palette, select Add Modules.
5. Select the Database connector in the right side of the Mule Palette and drag and drop it into the left
side.
6. If you get a Select module version dialog box, select the latest version and click Add.
91
7. Locate the new Database connector in the Mule Palette.
8. Drag and drop the Select operation in the process section of the flow.
Option 1: Configure a MySQL Database connector (if you have access to port 3306)
This section attempts to connect to a MySQL database and tests whether you are successful. A successful
connection requires access to port 3306. If you find that you cannot successfully connect, a second option is
described in the sections following this one that will allow you to locally host the database along with other
services that may be needed in the course.
9. In the Select properties view, click the Add button next to connector configuration.
92
10. In the Global Element Properties dialog box, set the Connection to MySQL Connection.
11. Set the host, port, user, password, and database values to the values listed in the course
snippets.txt file.
93
13. In the configure drop-down menu, select Add Maven dependency.
14. In the Maven dependency dialog box, locate the Search Maven Central text field.
94
16. Select mysql:mysql-connector-java in the results that are displayed.
95
20. Back in the Global Element Properties dialog box, click the Test Connection button; you should get
a successful test dialog box.
Note: If the connectivity test fails, make sure you are not behind a firewall restricting access to port
3306. If you cannot access port 3306, use the instructions in the next section for option 2.
Option 2: Run the MuleSoft training services application (if no access to port 3306)
If you were unable to connect to the MySQL database, the second option described here presents an
alternative solution that will allow you to locally host the database along with other services that may be
needed in the course.
23. In a command-line interface, use the cd command to navigate to the folder containing the jars folder
of the student files.
24. Run the mulesoft-training-services.jar file.
Note: Replace X.X.X with the version of the JAR file, for example 1.8.8.
Note: The application uses ports 1527, 9090, 9091, and 61616. If any of these ports are already in use,
you can change them when you start the application as shown in the following code.
96
25. Look at the output and determine whether all the services started successfully or if there was an
error.
Note: When you want to stop the application, return to this window and press Ctrl+C.
26. If the services started successfully, skip to the Option 2 (continued): Configure a Derby Database
connector section below.
97
Option 2 (continued): Set the Java environment to the Studio-embedded Java
27. Return to Anypoint Studio.
28. Open Anypoint Studio's Preference dialog.
98
30. Use the edit functionality to copy the value in the Location column for the Java 11 JRE then close
the Preference dialog.
Note: Be sure not to copy the location for the selected embedded JDK.
Windows
Mac:
31. Return to the open terminal window and set JAVA_HOME and Path.
Windows:
Mac:
99
32. From this same terminal, rerun the mulesoft-training-services.jar file.
33. Look at the output and make sure all the services started.
36. In the Global Element Properties dialog box, set the Connection to Generic Connection.
37. Set the URL and driver class name values to the Derby database values listed in the course
snippets.txt file.
100
38. Click the Configure button next to JDBC Driver.
39. In the configure drop-down menu, select Add Maven dependency.
40. In the Maven dependency dialog box, locate the Search Maven Central text field.
101
43. Click Edit selected.
44. Enter 10.14.2.0 in the Version text field.
Note: Version 10.14.2.0 is the latest Derby client compatible with Java 8 which is used by the Mule
runtime.
102
Write a query to return all flights
49. In the Select properties view, add a query to select all records from the american table.
SELECT *
FROM american
103
Walkthrough 4-3: Transform data
In this walkthrough, you transform and display the flight data into JSON. You will:
Starting file
If you did not complete the previous walkthrough, you can get a starting file here. This file is also located in the
solutions folder of the student files ZIP located in the Course Resources.
104
3. Drag the Transform Message component and drop it after the Select processor.
Note: If you are using the local Derby database, the properties will be uppercase instead.
105
Test the application
6. Save the file to redeploy the project.
7. In Advanced REST Client, send the same request; you should get a 200 response and the
American flight data represented as JSON.
Note: If you are using the local Derby database, the properties will be uppercase instead.
106
Review the data structure to be returned by the American flights API
8. Return to your American Flights API in Exchange.
9. Look at the example data returned for the /flights GET method.
10. Notice that the structure of the JSON being returned by the Mule application does not match this
example JSON format.
Define metadata for the data structure to be returned by the American flights API
11. Return to Anypoint Studio.
12. In the canvas, click the training4-american-wsFlow name.
13. In the training4-american-wsFlow properties view, select the Metadata tab.
107
14. Click the Add metadata button.
108
22. Click the browse button and navigate to the student files.
23. Select american-flights-example.json in the resources/examples folder and click Open; you should
see the example data for the metadata type.
109
Create the transformation
26. Map fields with the same names by dragging them from the input section and dropping them on the
corresponding field in the output section.
ID to ID
price to price
totalSeats to plane > totalSeats
27. Map fields with different names by dragging them from the input section and dropping them on the
corresponding field in the output section.
toAirport to destination
takeOffDate to departureDate
fromAirport to origin
seatsAvailable to emptySeats
planeType to plane > type
110
28. Concatenate two fields by dragging them from the input section and dropping them on the same
field in the output section.
code1 to code
code2 to code
111
30. In the Functions dialog box, select the trim function under dw:Core and examine the documentation
for it on the right side.
Note: You would normally select Finish to incorporate the selected function or operator into your
transformation.
112
Add sample data (optional)
34. Click the Preview button in the output section.
35. In the preview section, click the Create required sample data to execute preview link.
36. Look at the input section, you should see a new tab called payload with sample data generated
from the input metadata.
37. Look at the output section, you should see a sample response for the transformation.
113
Test the application
38. Save the file to redeploy the project.
39. In Advanced REST Client, make another request to http://localhost:8081/flights; you should see all
the flight data as JSON again but now with the example JSON format.
114
Walkthrough 4-4: Create a RESTful interface for a Mule
application
In this walkthrough, you continue to create a RESTful interface for the application. You will:
Starting file
If you did not complete the previous walkthrough, you can get a starting file here. This file is also located in the
solutions folder of the student files ZIP located in the Course Resources.
115
6. From the main menu bar, select Edit > Copy.
7. Click in the canvas beneath the flow and select Edit > Paste.
Note: If you want, change the name of the event source and event processors.
116
Specify a URI parameter for the new HTTP Listener endpoint
11. Double-click the HTTP Listener in getFlightsByID.
12. Modify the path to have a URI parameter called ID.
SELECT *
FROM american
WHERE ID = 1
Note: You did not add logic to the application to search for a flight with a particular ID. You will deploy
an application with this additional functionality implemented next.
117
Modify the database query to use the URI parameter
17. Return to the course snippets.txt file and copy the SQL input parameter expression.
18. Return to the getFlightsByID flow in Anypoint Studio.
19. In the Select properties view, locate the Query Input Parameters section, click the Switch to
expression mode button, then paste the expression you copied.
{'ID' : attributes.uriParams.ID}
20. Change the WHERE clause in the SQL Query Text to use this input parameter.
SELECT *
FROM american
WHERE ID = :ID
118
Test the application
21. Save the file to redeploy the project.
22. In Advanced REST Client, make another request to http://localhost:8081/flights/3; you should now
see the info for the flight with an ID of 3.
119
28. Set the path to /flights.
29. In the left-side navigation of the Listener properties view, select Advanced.
30. Set the allowed methods to POST.
120
31. Drag the Set Payload transformer from the Mule Palette and drop it in the process section of the
flow.
32. Return to the course snippets.txt file and copy the American Flights API - /flights POST response
example.
33. Return to Anypoint Studio and in the Set Payload properties view, click the Switch to literal mode
button for the value field.
Note: This flow is just a stub. For it to really work and add data to the database, you would need to add
logic to insert the request data to the database.
121
Test the application
35. Save the file to redeploy the project.
36. In Advanced REST Client, change the request type from GET to POST.
37. Click Send; you should get a 405 Method Not Allowed response.
38. Remove the URI parameter from the request URL: http://localhost:8081/flights.
39. Send the request; you should now see the message the flight was added – even though you did not
send any flight data to add.
122
Walkthrough 4-5: Use Anypoint Studio to create a RESTful
API interface from a RAML file
In this walkthrough, you generate a RESTful interface from the RAML file. You will:
Starting file
If you did not complete the previous walkthrough, you can get a starting file here. This file is also located in the
solutions folder of the student files ZIP located in the Course Resources.
123
4. In the User login dialog box, enter your username and password and click Sign In.
5. On the Authentication page, make sure your username is listed and selected.
6. Click Apply and Close.
9. In the Add Dependencies to Project dialog box, enter american in the search field.
124
10. Select your American Flights API (not the Training: American Flights API) and click Add.
Note: If you did not successfully create the American Flights API in the first part of the course, you can
use the pre-built Training: American Flights API connector.
11. In the selected modules, click American Flights API, then the 1.0.1 version then the version's down-
arrow.
Note: If you use the pre-built Training: American Flights API connector, select the latest version.
125
Examine the XML file created
18. Examine the generated american-flights-api.xml file and locate the following four flows:
delete:\flights\{ID}
get:\flights
get:\flights\{ID}
post:\flights
Note: You will also see a series of automatically generated components like the one shown here. These
are related to error handling.
126
19. In the get:\flights/{ID} flow, double-click the second Transform Message component and look at the
output JSON in the properties view.
20. In the get:\flights flow, double-click the Transform Message component and look at the output JSON
in the properties view.
21. In the post:\flights flow, double-click the Transform Message component and look at the output
JSON in the properties view.
127
Examine the main flow and its HTTP Listener
22. Locate the american-flights-api-main flow.
23. Double-click its HTTP Listener.
24. In the Listener properties view, notice that the connector configuration is the existing
HTTP_Listener_config and that path is set to /api/*.
25. Click the Edit button for the connector configuration; you should see that the same port 8081 is
used as the HTTP Listener you created previously.
26. Click Cancel.
128
Remove the other listeners
27. Select the Message Flow tab to return to the canvas for training4-american-ws.xml.
28. Right-click the HTTP Listener in getFlights and select Delete.
35. Click the Open console button; a browser tab should open with an API console.
129
36. Select the GET method for /flights and then click the Try it button if it's present.
37. Click Send; you should get a 200 response with the example flight data – not all the flights.
Note: If you use the pre-built Training: American Flights API connector, you must enter any values for
client_id and client_secret in the Headers section.
130
Test the web service using Advanced REST Client
39. Return to Advanced REST Client.
40. Change the method to GET and click Send to make a request to http://localhost:8081/flights; you
should get a 404 Not Found response.
41. Change the URL to http://localhost:8081/api/flights and send the request; you should get a 200
response with the example flight data.
Note: If you use the pre-built Training: American Flights API connector, you must add client_id and
client_secret headers with any values.
42. Make a request to http://localhost:8081/api/flights/3; you should see the example data returned for a
flight with an ID of 1.
131
Walkthrough 4-6: Implement a RESTful web service
In this walkthrough, you wire the RESTful web service interface up to your back-end logic. You will:
Starting file
If you did not complete the previous walkthrough, you can get a starting file here. This file is also located in the
solutions folder of the student files ZIP located in the Course Resources.
132
8. In the Mule Palette, select Core and locate the Components section in the right-side.
9. Drag a Flow Reference component from the Mule Palette and drop it into the process section of the
flow.
10. In the Flow Reference properties view, select getFlights for the flow name.
133
Use a Flow Reference in the /flights/{ID} resource
12. Delete both the Transform Message components in the get:\flights\{ID} flow.
13. Drag a Flow Reference component from the Mule Palette and drop it into the flow.
14. In the Flow Reference properties view, select getFlightsByID for the flow name.
18. In the resultant dialog, double-click get:\flights to navigate to the referencing flow.
134
Test the web service using Advanced REST Client
21. Save interface.xml to redeploy the project.
22. In Advanced REST Client, make a request to http://localhost:8081/api/flights; you should now get
the data for all the flights from the database instead of the sample data.
Note: If you use the pre-built Training: American Flights API connector, you must add client_id and
client_secret headers with any values.
23. Make a request to http://localhost:8081/api/flights/3; you should now get the data for that flight from
the database instead of the sample data.
135
Walkthrough 4-7: Synchronize changes to an API
specification between Studio and Anypoint Platform
In this walkthrough, you synchronize changes to an API specification between Anypoint Studio, Design Center,
and Anypoint Exchange. You will:
Starting file
If you did not complete the previous walkthrough, you can get an Anypoint Studio starting file here. If you have
not developed an American Flights API to add to your project, you can also get an API Designer starting
file here. These files are also located in the solutions folder of the student files ZIP located in the Course
Resources. Use these two starting files while following the steps in the addendum following this walkthrough.
Make the imported API specification editable in Anypoint Studio in a new API project
1. Return to the training4-american-ws project in Anypoint Studio.
2. Open american-flights-api.raml and try to make changes to the code; you should NOT be able to
make any changes.
136
3. Right-click american-flights-api.raml in the Package Explorer and select American Flights API > Edit
API specification.
137
Locate the new API project created in Anypoint Studio
6. Locate the new american-flights-api project that was created in the Package Explorer; its american-
flights-api.raml file should have automatically opened.
138
Review the Git Staging view for the API project
13. Locate the new Git Staging view that opened in Anypoint Studio.
14. Examine the Unstaged Changes section; you should see the american-flights-api.raml file that is
not yet staged for synchronization.
Review the API specification that was imported into the Mule project
15. Return to the training4-american-ws project.
16. Review the american-flights-api.raml file in that project; you should NOT see the new put method.
139
Push the changes for the modified API from Anypoint Studio to Design Center
17. Return to the Git Staging view.
18. Click the Add selected files to the index button in the upper-right corner of the Unstaged Changes
section; the american-flights-api.raml file should move from the Unstaged Changes section to the
Staged Changes section.
19. In the Commit Message section, enter the text Add PUT method.
20. Click the Commit and Push button; the Staged Changes section should now be empty.
140
21. In the Push Results dialog box, examine the commit log messages.
Note: If you do not see the PUT method, refresh the page.
141
Publish the modified API to Exchange from Anypoint Studio
25. Return to Anypoint Studio.
26. In the Package Explorer, right-click the american-flights-api project and select Manage API
Specification > Publish to Exchange.
27. In the API configuration dialog box, notice that Last published version is 1.0.1.
28. Set the Asset version to 1.0.2.
Note: If you do not see the 1.0.2 asset version, refresh the page.
142
Update the API portal information
36. Click the Edit documentation button.
37. Add the new update a flight operation.
Review the API specification that was imported into the Mule project again
39. Return to the training4-american-ws project in Anypoint Studio.
40. Locate the American Flights API in the training4-american-ws project and notice that it is still v1.0.1.
143
41. Review the american-flights-api.raml file; you should still NOT see the new put method.
Update the version of the API used in the Mule project and rescaffold the flows
42. Right-click American Flights API in the training4-american-ws project and select American Flights
API > Update Version.
144
43. In the Properties for training4-american-ws dialog box, select the American Flights API; an Update
version button should appear.
44. Click Update version; the version of the API should change to 1.0.2.
145
47. When the scaffolding is complete, review the flows in interface.xml; you should now see five
method flows, including the new put:\flights\{ID} method.
48. Look at the get:\flights\{ID} method; it was not overwritten and still has your change to use a Flow
Reference component.
Starting File Addendum (only needed if you did not complete Walkthrough 4-6)
Create your editable API in Exchange with the correct asset number
1. In API Designer, create American Flights API then import wt3-4_American-Flights-API_solution.zip
electing to replace american-flights-api.raml.
2. Publish the API to Exchange with an asset/version of 1.0.1/v1 and a stable lifecycle state.
Create your Studio application and replace the static API with your editable API
3. In Studio, import wt4-6_training4-american-ws_solution.jar.
4. Right-click the project and select Manage Dependencies > Manage APIs to delete Training:
American Flights API and to add your American Flights API from Exchange.
146
Transfer the flow references from the old scaffold to the new
5. Copy/paste the flow reference from interface.xml get:\flights to its corresponding location in
american-flights-api-2.xml replacing any transforms.
6. Repeat for the get:\flights\(ID) flow reference.
Note: When using these starting files, walkthrough steps such as updating the API portal information in
Exchange may not match the screenshots.
147
Module 5: Deploying and
managing APIs
148
Walkthrough 5-1: Deploy an application to CloudHub
In this walkthrough, you deploy and run your application on CloudHub. You will:
Note: If you do not have a working application at this point, import the wt4-7_training4-american-
ws_solution.jar solution into Anypoint Studio and work with that project.
Starting file
If you did not complete the previous walkthrough, you can get a starting file here. This file is also located in the
solutions folder of the student files ZIP located in the Course Resources.
149
3. In the Choose Environment dialog box, select Sandbox.
Note: If you get a dialog asking to enable multi-factor authentication, click Not Now.
4. At the top of the Anypoint Platform dialog box, set the application name to
training4-american-ws-{your-lastname} so it is a unique value.
Note: This name will be part of the URL used to access the application on CloudHub. It must be unique
across all applications on CloudHub. The availability of the domain is instantly checked and you will get
a green check mark if it is available.
6. Make sure the runtime version is set to the version your project is using and that the worker size is
set to 0.1 vCores.
Note: If you don’t know what version it is using, look at the Package Explorer and find a library folder
with the name of the server being used, like Mule Server 4.4.0 EE.
150
8. Click the Open in Browser button (you don't have to wait for your application to fully deploy).
Note: The Runtime Manager dialog box which contains this button may take some time to appear.
9. In the Anypoint Platform browser window that opens, choose Sandbox for an environment then
locate the status of your deployment in the Runtime Manager.
151
13. Wait until the application starts (or fails to start).
Note: If your application did not successfully deploy, read the logs to help figure out why the application
did not deploy. If you had errors when deploying, troubleshoot them, fix them, and then redeploy.
Note: {region} represents the worker region to which the Mule application is deployed. In North
America, the default region is US East and is denoted by us-e2 in the application URL.
16. Click the link; a GET request will be made to that URL in a new browser tab and you should get a
message that there is no listener for that endpoint.
152
17. Modify the path to http://training4-american-ws-{lastname}.{region}.cloudhub.io/api/flights; you
should see the flights data.
Note: If you are using the local Derby database, your application will not return results when deployed
to CloudHub. You will update the application with a version using the MySQL database in the next
section, so it works.
18. Add a query parameter called destination to the URL and set it equal to SFO.
19. Send the request; you should still get all the flights.
Note: You did not add logic to the application to search for a particular destination. You will deploy an
application with this additional functionality implemented next.
153
Update the API implementation deployed to CloudHub
21. Return to the browser tab with Runtime Manager.
22. In the left-side navigation, select Settings.
23. Click the Choose file button and select Upload file.
24. Browse to the jars folder in the student files.
25. Select training4-american-ws-v2_SP.jar and click Open.
Note: The filename differs slightly for instructor-led and self-study training classes.
Note: This updated version of the application adds functionality to return results for a particular
destination. You will learn to do this later in the Development Fundamentals course.
27. Wait until the application is uploaded and then redeploys successfully.
Note: Because this can take some time for trial accounts, your instructor may move on with the next
topic and then come back to test this later.
154
Test the updated application
29. Return to the browser tab with a request to the API implementation on CloudHub with a destination
of SFO and refresh it; you should now get only flights to SFO.
155
Walkthrough 5-2: Create and deploy an API proxy
In this walkthrough, you create and deploy an API proxy for your API implementation on CloudHub. You will:
Starting file
This walkthrough uses Anypoint Platform. There is no starting file. To complete the walkthrough, you must
have completed the preceding walkthrough.
3. Click the Add API button and select Add new API.
156
4. On the APIs / Add API page, select the Mule Gateway button for the Runtime settings.
7. Click Next.
157
8. For the API settings, ensure Select API from Exchange is selected then select your American
Flights API in the Select API section.
9. Ensure the rest of the API settings fields are set to the following values:
158
12. Expand Advanced options and examine the additional fields and values.
13. Click Next.
14. Review the Add API settings and click Save & Deploy.
Note: If it does not successfully deploy, examine the logs for your proxy application in Runtime
Manager to help figure out why the application did not deploy. If you had errors when deploying,
troubleshoot them, fix them, and then redeploy.
159
16. Locate and review the links in the upper-right corner.
17. Select Manage CloudHub Proxy: a new browser tab should open with your new proxy application in
Runtime Manager.
18. In the left-side navigation, select Applications; you should see the proxy application listed along with
your original application deployed from Anypoint Studio.
19. Click the row for the proxy and review its information in the right section of the window.
160
View API details in API Manager
21. Return to the tab with API Manager and review the API proxy information at the top of the page.
22. In the left-side navigation, click the API Administration link; you should now see your American
Flights API listed.
23. In the API list, click the name of the API; you should be returned to the Settings page for the API.
161
24. Click the View configuration details link in the upper-right corner.
26. On the Settings page, look at the requests graph in the Key Metrics section; you should not see any
API requests yet.
162
View the new API proxy instance in Exchange
27. Return to the browser tab with Exchange.
28. Return to the home page for your American Flights API.
29. Click the Manage versions button to locate the API instances now associated with asset version
1.0.2; you should see the Mocking Service instance and now the new proxy.
Note: You may need to refresh your browser page before clicking Manage versions.
33. In the left-side navigation, select API instances; you should see that the new proxy instance does
not have a URL.
163
Set a friendly label for the API instance in API Manager
34. Return to the browser tab with API Manager.
35. On the Settings page for your American Flights API, click the Add a label link.
36. Set the label to No policy and press Enter/Return.
164
Make requests to the API proxy from Exchange
42. Return to the browser tab with Exchange.
43. Refresh the API instances page for your American Flights API; you should see the new label and
the URL.
44. In the left-side navigation, select Home to return to the API's main page.
45. Click the Manage versions button to locate the API instances now associated asset version 1.0.2;
you should see the new label for the API instance.
165
49. Select the Sandbox - No policy instance.
50. Click the Send button; you should now see the real data from the database, which contains multiple
flights.
166
Make an API instance visible in the public portal
56. Return to the browser with Exchange.
57. In the left-side navigation for American Flights API, select API instances.
58. Change the visibility of the No policy instance from private to public.
62. Click Send; you should a 200 response and flight data.
167
65. Look at the Request chart again; you should now see data for some API calls.
66. Click the View Analytics Dashboard link located in the upper-right corner.
67. In the Date Range drop-down menu near the upper-left corner, select 1 Hour.
68. Review the data in the dashboard.
168
Walkthrough 5-3: Restrict API access with policies and
SLAs
In this walkthrough, you govern access to the API proxy. You will:
Starting file
This walkthrough uses Anypoint Platform. There is no starting file. To complete the walkthrough, you must
have completed the preceding walkthrough.
169
2. In the left-side navigation, select Policies.
6. Click Next.
7. On the Configure Rate limiting policy page, set the following values and click Apply:
Number of Requests: 3
Time Period: 1
Time Unit: Minute
170
8. Select Expose Headers.
9. Expand Advanced options and examine the additional fields and values.
10. Click Apply; you should see the policy listed under API-level policies.
171
Test the new rate limiting policy
13. Return to the browser tab with your American Flights API in Exchange.
14. In the left-side navigation, select the /flights GET method.
15. Select the Sandbox – Rate limiting policy API instance.
Note: You may need to refresh the page to see the new label for the API instance.
16. Press Send until you get a 429 Too Many Requests response.
172
20. In the Add SLA tier dialog box, set the following values:
Name: Free
Approval: Automatic
# of Reqs: 1
Time Period: 1
Time Unit: Minute
Name: Silver
Approval: Manual
# of Reqs: 1
Time Period: 1
Time Unit: Second
173
Change the policy to rate limiting – SLA based
23. In the left-side navigation, select Policies.
24. In the Rate limiting policy options menu, select Remove policy.
174
30. Click Apply; you should see the policy listed under API-level policies.
31. In the left-side navigation, select Settings.
32. Change the API instance label to Rate limiting – SLA based policy.
175
Walkthrough 5-4: Request and grant access to a managed
API
In this walkthrough, clients request access to an API proxy and administrators grant access. You will:
Request application access to SLA tiers from private and public API portals.
Approve application requests to SLA tiers in API Manager.
Starting file
This walkthrough uses Anypoint Platform. There is no starting file. To complete the walkthrough, you must
have completed the preceding walkthrough.
176
3. Click the Request access button near in the upper-right corner.
Note: Other internal users that you shared the API with that do not have Edit permissions will see a
different menu.
4. In the Request access dialog box, select Rate limiting - SLA based policy in the API Instance drop-
down menu.
5. Click the Create a new application link in the Application drop-down menu.
177
6. In the Create new application dialog box, set the name to Training internal app and click Create.
7. In the Request access dialog box, set the SLA tier to Free.
178
9. In the Request API access dialog box, you should see that your request has been approved; view
the assigned values for the client ID and client secret.
13. Click Login in the upper-right corner; you should get a page to sign in or create an Anypoint
Platform account.
14. Enter your existing credentials and click Sign in.
Note: Instead of creating an external user, you will just use your existing account.
179
15. Back in the public portal, click the Request access button.
16. In the Request access dialog box, select Rate limiting - SLA based policy in the API Instance drop-
down menu.
17. Click the Create a new application link in the Application drop-down menu.
18. In the Create new application dialog box, set the name to Training external app and click Create.
19. In the Request access dialog box, set the SLA tier to Silver.
180
22. In the portal main menu bar, right-click My applications and select to open the link in a new tab; on
the new tab, you should see the two applications you created.
23. Click the link for Training external app; you should see what APIs the application has access to,
values for the client ID and secret to access them, and request data.
24. Leave this page open in a browser so you can return to it and copy these values.
181
27. Click the Approve button for the application requesting Silver tier access.
28. Expand the Training external app row and review its information.
29. Copy the value of the Client ID.
Add authorization headers to test the rate limiting – SLA based policy from an API portal
30. Return to the private/incognito browser window and tab with the American Flights API portal in the
public portal.
31. Try again to make a call to the Sandbox – Rate limiting – SLA based policy; you should still get a
401 Unauthorized response.
32. In the Headers section, click the Add link.
33. Set the header name to client_id.
34. Set the value of client_id to the value you copied.
35. Return to the browser tab with My applications in the public portal.
36. Click the Show link next to Client Secret then copy its value.
37. Return to the browser tab with the API console in the public portal.
38. Add another header and set the name to client_secret.
182
39. Set the client_secret header to the value you copied.
40. In the course snippets.txt file, record these client_id and client_secret values in the section reserved
for this module.
41. Click Send; you should now get a 200 response with flight results.
183
Walkthrough 5-5: Add client ID enforcement to an API
specification
In this walkthrough, you add client ID enforcement to the API specification. You will:
Modify an API specification to require client id and client secret headers with requests.
Update a managed API to use a new version of an API specification.
Call a governed API with client credentials from API portals.
Note: If you do not complete this exercise for Fundamentals, the REST connector that is created for the
API and that you use later in the course will not have client_id authentication.
Starting file
This walkthrough uses Anypoint Platform. There is no starting file. To complete the walkthrough, you must
have completed the preceding walkthrough.
184
3. In the Rate limiting – SLA based policy options menu, select API Specification snippet.
4. On the API specification for Rate limiting - SLA based page, select the RAML 1.0 tab.
5. Copy the value for the traits.
6. In the API Manager asset path near the top of the page, click American Flights API.
185
Add authentication headers to the API specification
7. Return to the browser tab with your API in Design Center.
8. Go to a new line after the types declaration and paste the traits code you copied.
is: []
186
11. Make sure the cursor is inside the array brackets and add the client-id-required trait name as an
array element.
12. Repeat this process so the trait is applied to all methods of the {ID} resource as well.
187
16. Enter any values for the client_id and client_secret and click Send; you should get a 200 response
with the example results.
188
Update the managed API instance to use the new version of the API specification
20. Return to browser tab with American Flights API v1 in API Manager.
21. Refresh the page then locate the asset version displayed at the top of the page; you should see
1.0.2 and a new Update drop-down menu next to it.
23. In the Update asset version dialog box, select 1.0.3 (Latest) in the drop-down menu.
24. Click Change; you should see the 1.0.3 asset version displayed at the top of the page with the
Latest label next to it.
Note: You may need to refresh the page to see the new version and label.
189
Test the rate limiting – SLA based policy in the API console in Exchange
25. Return to the browser tab with Exchange.
26. Return to the home page for the API and click the Manage versions button; you should see the new
version listed with instances for both the Mocking Service instance and the new proxy.
Note: You will test and use the authentication with the REST connector later in the Fundamentals
course.
190