{api:dab}: Bringing the power of APIs to micro, small and medium-sized enterprises

GET METHOD: Calling your {api:dab} API

Our Test API Overview

For the purposes of this demo, we have taken a data-set comprised of the ISO Currency codes for individual countries and created a simple API that is feature-rich, right out of the box. This API was timed and took less than ten minutes to create, including the uploading of the source data. You will see below that we can perform a full listing, or sort and/or filter by specific data fields. In standard form, the APIs that you can build are designed to be case insensitive and support partial data in the search parameter. This effectively allows the useful feature of wild card searching across data. For security reasons, the data is served from your own database (no resource is shared with other {api:dab} clients), so you can be sure of excellent and scalable performance for your implementation. The fields of data provided by the API are listed below:

  • CURRENCY (e.g. Pound Sterling)
  • COUNTRY (e.g. Guernsey)
  • ALPHACODE (e.g. GBP)
  • NUMCODE (e.g. 826)

In our examples we are pulling the data to our chosen browser via the URL line. This is for the convenience of the demonstration, but equally, we could pull this data into a web application via almost any modern application development tool or a use a webpage embedded AJAX object to update our application fields without having to refresh the whole page.

 

Functionality Examples

Our first 'call' to the API service will be to pull all data that the API exposes, so we end up with a full list that can be taken into our target web application or mobile app. This is particularly useful when leveraged by your clients as a replacement for data imports; the data will be accurate and timely with much reduced failure vectors. It is important to note that, by default, the API will only allow a maximum of 8,000 records to be returned. This setting can be changed on the platform to suit, but to mitigate excessive server loads or possible denial of service attacks, it is always preferable to set an appropriate value. To list all data we simply pass the following address and parameters via a URL:

Click Link One: https://yourcompanyname.apidab.com/get/q.cfm?IDToken=60FD6C8D-9F51-4511-93E0-2DDC5413E576

So let us break down the parameters (instructions) we are sending to our API at web address yourcompanyname.apidab.com/get/q.cfm:

  • METHOD: The endpoint for this API is located at /get so we are exposing the GET method to our users.
  • IDTOKEN All users of your API will be automatically issued with a string that needs to be passed to ensure their identify. In the absence of the idtoken, the API will refuse the connection, assuming that the remote user in not authorised to view the data.

Click on Link One to see to the results of our query in a new browser window. You will notice that the sort order defaults to 'by COUNTRY'.

If we do not want to use the default sort order, you can change this to 'by ALPHACODE' by also passing the SORT (by) and SORTDIR (direction - ASC/DESC) parameters to the URL as below, with Link Two:

Click Link Two: https://yourcompanyname.apidab.com/get/q.cfm?IDToken=60FD6C8D-9F51-4511-93E0-2DDC5413E576&sort=alphacode&sortdir=asc

Great - that was easy - we now have an API that a client could use to obtain a full list of data, sorted to suit. In this case we are looking at currency data, but equally, this could be a list of stock and prices to be consumed by the client system.

In another example, we are going to imagine that the client doesn't want to pull our entire data-set into their own system, but actually wants to embed our data somewhere in their own web page. In this case, they probably only want to show a specific record of our data-set that matches their page. To illustrate this, in our example, let us imagine that they have a page for worldwide offices and they want to embed the local currency name and ISO Code for a given country - they could ammend the parameters to include:

Click Link Three: https://yourcompanyname.apidab.com/get/q.cfm?IDToken=60FD6C8D-9F51-4511-93E0-2DDC5413E576&search=ECUADOR

By passing the COUNTRY value of ECUADOR to the API, you will notice that it is now only passing relevant records to the browser. When we pass data to the search parameter, it will search across all our data fields for a match and will automatically treat te data as a potential wildcard, so it is better to be very specific where you need to only return one singe match.

Therefore, if we wanted to display any country that contained the word 'state' in the name, we could do this:

Click Link Four: https://yourcompanyname.apidab.com/get/q.cfm?IDToken=60FD6C8D-9F51-4511-93E0-2DDC5413E576&search=STATE

In this case, our results look like:

  • BOLIVIA (PLURINATIONAL STATE OF)
  • HOLY SEE (VATICAN CITY STATE)
  • MICRONESIA (FEDERATED STATES OF)
  • UNITED STATES OF AMERICA (THE)

Our final example, we are going to list all countries of the World that use the Euro as a currency and then sort by ALPHACODE in ascending order:

Click Link Five: https://yourcompanyname.apidab.com/get/q.cfm?IDToken=60FD6C8D-9F51-4511-93E0-2DDC5413E576&search=EUR&sort=country&sortdir=asc

Our Euro list would include the details for the following countries:

  • ANDORRA
  • AUSTRIA
  • BELGIUM
  • CYPRUS
  • ESTONIA
  • FINLAND
  • FRANCE
  • etc...

 

AJAX Version: Customers might access the API this way...

If your customer were to embed our API into their own web application pages, they may well use AJAX calls similar to that below:

$(function() {
let url = 'https://yourcompanyname.apidab.com/get/q.cfm';
let table = $("#ccytable").children('tbody');
$.ajax({
url: url,
type: 'GET',
dataType: 'json',
headers: {"IDToken":"60FD6C8D-9F51-4511-93E0-2DDC5413E576"},
success: function(data) {
data.forEach(element => {
table.append($('')
.append($('').append(element.UUID))
.append($('').append(element.Country))
.append($('').append(element.Currency))
.append($('').append(element.AlphaCode))
.append($('').append(element.NumCode))
);
});
}
});
})

 

POST METHOD: Collecting Data for your {api:dab} API

Allowing Internal or External Parties to Add New Data

Above we created and securely published a simple read-only API comprised of only four fields of data. Now we are going to demonstrate how your clients or internal departments can securely post new records to the same API, if that functionality is required. For this example, we will take another use case where we are collecting data for a claims reporting system:

  • CLAIM REFERENCE
  • MPL
  • CLAIM RESERVE
  • CLAIM PAID
  • STATUS

In addition to adding data, our clients could also be updating existing records, if that is a requirement. But, for the purposes of this demo we will only focus on adding new records. As with the GET method, our client could use a different version of an AJAX component to POST new records to the API:

AJAX Version: Customers might POST to the API this way...

var postData = {
ClaimRef: "PI20998227732",
MPL: 120000,
ClaimReserve: 65000,
ClaimPaid: 15000,
Status: "Open"
};
var ajaxResponse = $.ajax({
type: "post",
headers: {"IDToken":"60FD6C8D-9F51-4511-93E0-2DDC5413E576"},
url: "https://yourcompanyname.apidab.com/post/q.cfm",
contentType: "application/json",
data: JSON.stringify( postData )
})
ajaxResponse.then(
function( apiResponse ){
$( "#response" ).html( apiResponse );
}
);

 

We hope you found these examples of the simple, but powerful functionality that the {api:dab} platform enables, right out of the box. Why not sign up for your free trail and use some of your own ideas to extend the reach of your existing IT systems.

{api:dab}: Publish data via API in minutes!