1. Creating a Mule project
with RAML and API Kit
Router
BHARGAV RANJIT S
2. Application programming interface(APIs)
In computer programming, an application programming interface (API) is a
set of subroutine definitions, protocols, and tools for building software and
applications. A good API makes it easier to develop a program by providing
all the building blocks, which are then put together by the programmer. An
API may be for a web-based system, operating system, database
system, computer hardware, or software library. An API specification can
take many forms, but often include specifications for routines, data
structures, object classes, variables, or remote
calls. POSIX, Microsoft Windows API, the C++ Standard Template Library,
and Java APIs are examples of different forms of APIs. Documentation for
the API is usually provided to facilitate usage.
3. Types of APIs
There are many different types of APIs for operating systems, applications or websites.
Windows, for example, has many API sets that are used by system hardware and
applications — when you copy and paste text from one application to another, it is the
API that allows that to work.
Most operating environments, such as MS-Windows, provide APIs, allowing
programmers to write applications consistent with the operating environment. Today,
APIs are also specified by websites. For example, Amazon or eBay APIs allow
developers to use the existing retail infrastructure to create specialized web stores.
Third-party software developers also use Web APIs to create software solutions for
end-users.
4. Popular API Examples
ProgrammableWeb, a site that tracks more than 15,500 APIs, lists Google Maps, Twitter,
YouTube, Flickr and Amazon Product Advertising as some of the the most popular APIs. The
following list contains several examples of popular APIs:
1. Google Maps API: Google Maps APIs lets developers embed Google Maps on webpages
using a JavaScript or Flash interface. The Google Maps API is designed to work on mobile
devices and desktop browsers.
2. YouTube APIs: YouTube API: Google's APIs lets developers integrate YouTube videos and
functionality into websites or applications. YouTube APIs include the YouTube Analytics API,
YouTube Data API, YouTube Live Streaming API, YouTube Player APIs and others.
3. Flickr API: The Flickr API is used by developers to access the Flick photo sharing community
data. The Flickr API consists of a set of callable methods, and some API endpoints.
4. Twitter APIs: Twitter offers two APIs. The REST API allows developers to access core Twitter
data and the Search API provides methods for developers to interact with Twitter Search and
trends data.
5. Amazon Product Advertising API: Amazon's Product Advertising API gives developers access
to Amazon's product selection and discovery functionality to advertise Amazon products to
monetize a website.
5. Explore the ProgrammableWeb API
directory
1. In a web browser, navigate to http://www.programmableweb.com/.
2. Click the API directory link.
3. Scroll down and click the link for the Twitter API.
Note: If Twitter is no longer displayed on the main page, search for it.
4. In the Specs section, click the API Homepage link.
5. Browse the list of requests you can make to the API.
8. “Three-layered” API-led connectivity
architecture
Large enterprises have complex, interwoven connectivity needs that require
multiple API-led connectivity building blocks. In this context, putting in a
framework for ordering and structuring these building blocks is crucial.
Agility and flexibility can only come from a multi-tier architecture containing
three distinct layers:
System Layer -Owned by Central IT (6-12 months )
Process Layer -Owned by Central IT and Line of Business IT (3-6 months)
Experience Layer -Line of Business IT and Application Developers (4-8
weeks; more frequently for more mature companies)
10. What is RAML?
The most simplest way to design APIs
RESTful API Modeling Language (RAML) makes it easy to manage the
whole API lifecycle from design to sharing. It's concise - you only write
what you need to define - and reusable. It is machine readable API
design that is actually human friendly.
More about RAML- http://raml.org/
12. Using API Designer to define an API with
RAML
Open https://anypoint.mulesoft.com and log in.
Click the menu button located in the upper-left in the main menu bar.
In the menu that appears, click Anypoint Platform; this will return you to the home page.
Note: This will be called the main menu from now on.
In the main menu, select API Manager.
Click the Add new API button.
In the Add API dialog box, enter the necessary information.
Click Add.
Look at the different sections and links for the API on the API administration page.
Click the API administration link in the main menu; you should see your new API listed.
Click the row containing version 1.0 of your API; you should see details for it displayed on the right.
Click the version 1.0 link for the API; you should return to the details page for that API.
13. Creating an API portal
Just like a portal shown previously for Twitter API,you create an API portal for
developers to locate, learn about, and try out the API.
This can be done using the API portal tab under API manager using your Anypoint
platform account.
14. Running API in Anypoint Studio
To create a new project:
Create and save an example api.raml file to your local drive.
Under the File menu, select New > Mule Project.
In the New Mule Project wizard, enter a Name, myproject for example, and
accept the default Mule Runtime 3.8.0.
Check Add APIkit components. In the RAML file field, browse to and select
the created RAML file.
Click Finish.
Studio launches the new project and generates a Main flow with an HTTP
Listener, an APIkit Router, and reference to the APIkit exception strategy
mappings. Backend flows also appear. The RAML file you imported resides in
src/main/api.
16. Running and Testing the created API
Project in Anypoint Studio
Right-click the project name in the Project Explorer, then select Run
As > Mule Application.
The APIkit Console appears below the canvas, displaying the resource-
action pairs exposed by the API.
Click Introduction under DOCUMENTATION to view the API description.
Click the GET button to send a test call to GET a list of machines.
The API returns a list of machines.
The output is the payload set on the message by the
get:/machines:apiConfig flow.
18. Adding an API to the Anypoint Exchange
You can enhance the discoverability of an API by adding it to the private
Anypoint Exchange. You can:
Give yourself permission to publish items on the Exchange.
Add a new RAML API to the private Exchange.
Submit an item for approval.
Approve and publish an item to the private Exchange.