Lab 1: Import the RAML Definition into Studio
Overview
In this lab, we will create the skeleton implementation of our Customer API that will process requests to Salesforce. You will use Anypoint Studio to create a Mule application that will have one flow for each method of each resource (i.e. GET customers). Additionally you will use APIKit (as part of your Mule application) to process REST requests, transform them to messages to be handled and processed by each flow.
The implementation will consist of a few steps:
Step 1: Create a new Mule Project and import RAML Definition
We are going to use our API definition to create an implementation of our Customer API. To do this we need to import the RAML Specification from the Design Center
- If it’s not already opened, start Anypoint Studio from the desktop icon and select the same workspace you’ve been working (example: C:\workspaces\myworkspace).
- From Anypoint Studio’s menu, select File > New > Mule Project to create a New Mule project. A Window will pop-up to define the details of this new application.
- Give the project the name customer-api
- Select the Mule Server 4.4.0 EE (or latest version available).
Under Import a Publish API we are going to import the RAML Spec from Exchange. Click on
and select from Exchange
Once you clicked there, you will see a new window. If you don’t see any username. You need to login to the Anypoint Platform. So click on the Add Account button.
Ignore any popup about secure storage or any other that may be displayed during loggin
This is the same thing you did in the last module. You will see a list with all the APIs Select Customer API published by your workshop business gropup (you might find it easier if you type “Customer API” with quotes) and press Add.
Be sure when you select the Customer API. Validate that the Publisher has the name of the workshop business group.
Press Finish.
Check everything is fine. Be sure that the Scaffold flows from these API Specifications is checked. Press Finish.
APIkit creates your new Anypoint Studio project with a generated implementation based on your API specification. The generated configuration implements the inbound HTTP listener, as well as, all the resources, request/response data type metadata, among other thing
Step 2: Run the API
To test the API, let’s run it within Studio. Right click on the application in the Package Explorer view.
Select Run As > Mule Application. (Feel free to skip this if you’ve done this in the previous lab).
Every time we start the application, we need to make sure that it is started successfully. Check in the Console tab that the project appears as “DEPLOYED”.
Once the application is deployed, Anypoint Studio will open a tab with the APIkit Consoles where we can test the application (to access the console, just click the link to open the Customer API Console in a browser).
Click the POST method under
/customer
and test the customer creation.In the Accept field complete with
application/json
Press the Send Button.
Scroll down the third panel and you will see the sample response defined in the API specification.
Go to the console tab and press the red button to stop the Mule runtime server.
Summary
In this lab, we
- Import the RAML Definition directly into Anypoint Studio
- Auto-generated a skeleton project to implement the API
- Run the skeleton project and tested it via the API Console
Go Further:
- See the link APIkit doc for more information.
Congratulations! You have completed Lab 1.
Please proceed to Lab 2