Connector Development through REST Connect Tool
MuleSoft Connectors
MuleSoft connector specifies the packaged functionality of an API or service in a reusable and easily discoverable format. Connector development is a very large and wide area in MuleSoft and each of the current functionality of MuleSoft is based on different connectors.
Frequently used connectors:
- Salesforce Connector
- Database Connector
- HTTP Connector
MuleSoft connector abstracts the implementation and exposes only endpoints to the user. Mule also has the capability to restructure the data format to an acceptable form.
Connector Development.
Connector development can done through different ways in Mule, few of them are given below:
- Using Java JDK and Mule HTTP Client
- Using XML SDK and Java
- REST Connect tool
In the above list one of the efficient ways of connector development is through the REST Connect Tool.
REST Connect Tool:
It’s a RAML based tool to generate a connector with simple functionality. In this method you can add some security and masking for your API endpoints. This method can be mainly used for developing internal reusable components.
Creating a Connector
Let us take Google Place Search API for creating a connector
Requirement:
- Google API URL
- Google API KEY
- Anypoint platform login and designer center access
- Postman for testing the endpoint
- Anypoint studio for generating demo project
Choose an API which we are going to use for developing the connector
https://developers.google.com/maps/
documentation/geocoding/intro
As next step we have to create Google API key
Once endpoint is validated, go to Anypoint Design Center to start RAML coding.
In Design Center go to Create API Specification and create your new application and provide your application name.
Now, the RAML will be visible for you to edit. here is an example for the below RAML specifications:
- RAML version
- Base URI
- HTTP Method
- Base Path
- URI, Query and Body Parameters
- Request/Response
- Error Types
#%RAML 1.0
title: GoogleAPI-Connector
baseUri: https://maps.googleapis.com/maps/api/
mediaType:
- application/json
version: 1
/geocode/json:
displayName: Get Address
get:
queryParameters:
address :
type: string
required: true
default: India
key :
type: string
required: true
description: Google API key
responses:
200:
body:
application/json:
422:
body:
application/json:
400:
description: Error
body:
application/json:
500:
description: Internal server error
body:
application/json:
Copy paste this in your RAML file and try with Mocking service and publish into your exchange (It will deploy your project in your local exchange)
Now our API is deployed into an Exchange, you can verify in API Exchange.
Choose API Spec Base URI,Pass the required parameter and test.
To use a custom connector inside your Anypoint Studio and test it use the following steps.
- Open your Anypoint Studio -> Create a new Project. Add your HTTP Listener and configure
- Click on Search in Exchange (right hand top). Click on Add Account and pass your Anypoint platform login credentials
- Next step is to Search Google API Connector and add it into your project
- Drag and drop your connector and pass the required parameters and build
- Call the endpoint 8081/search in postman