Client Code Generation in Test&Doc APIs

54

This new utility consists of a client code editor for the APIs of the Ontologies in the most popular programming languages, in this way we will only have to copy the code that it generates and insert it in our applications.

For this we must access the API of the Ontology that we want to invoke. In this example, it will be “APARCAMIENTOSPUBLICOSMADRIDES “. So we will access the “API MANAGER” menu, and the “APIs” submenu:

Image 001

Once here, we go to “My Subscriptions” tab:Image 004

We choose the API that we want to test. And click on the “Test & Doc” button:Image 007

Here we have information about the API and the functions it exposes for its consumption. We are going to choose the “getAll” function:

Image 010

Next we are shown the information referring to that function, and on the right part a drop-down menu called “API Invocation” will appear, in which we will choose the language we want to use to invoke the function:

Image 013

And this will generate the piece of code needed to invoke the function. We will only have to complete this code using the logged user’s token in the “x-sofia2-apikey” part:

Image 016

I have created a sample page in HTML using JQuery, to insert the code that generates us for the API method, the HTML code used for the example would be:

<code>

<!DOCTYPE html>
<html>

<head>
<meta charset=”UTF-8″>
<title>Test API</title>
http://code.jquery.com/jquery-2.2.3.min.js

$(document).ready(function() {
$(“#myButton”).click(function() {

var settings = {
“async”: true,
“crossDomain”: true,
“url”: “https://sofia2.com/sib-api/api/v1/aparcamientospublicosmadrides/getAll&#8221;,
“method”: “GET”,
“headers”: {
“x-sofia2-apikey”: “********************”
}
}

$.ajax(settings).done(function (response) {
console.log(response);
var num = response.data.length;
$(“#helloWorldDiv”).html(“Request URL: https://sofia2.com/sib-api/api/v1/aparcamientospublicosmadrides/getAll
Num Result: ” + num);

});

});
});

</head>

<body>
<button id=”myButton”>Test API</button>
</br>
</br>

</body>

</html>

</code>

result could be something like this:

Image 028

Client Code Generation in Test&Doc APIs

Responder

Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Cerrar sesión /  Cambiar )

Google+ photo

Estás comentando usando tu cuenta de Google+. Cerrar sesión /  Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión /  Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión /  Cambiar )

Conectando a %s