Workshops

Workshop on the Platform. Part V: API Rest

To finish with the Platform Workshop, you are going to use the API Manager to create a REST API that allows you to know which stations have available bikes below a threshold that is passed by parameter. To do this, create an operation that will query, through a SQL sentence in the ontology BicingBCN_Status, which stations are below the threshold.

Access the API Manager from the menu Development > My APIs and select «Create». In the form, specify the API data: Identification, category, description, meta-information, and select that it is an Ontology as REST API, then we indicate that the exposed ontology is «BicingBCN_Status»:

Next, indicate that you want to create an operation of «Custom Query» type. In the form that opens, fill in the operation identifier, the parameterized SQL sentence, the parameter data type and the operation description:

The query to use is this one:

select * from BicingBCN_Status as b where c.BicingBCN_Status.numBikesAvailable > {$param}

If you save the API, it will be created and the newly created operation can be invoked. To do so, retrieve the user’s token from the menu option Development > My Apis and select the tab «User Tokens»:

Testing the API

From the menu option Development > My Apis, find the API in the list and select the option «Swagger»:

In the next screen, make sure that the scheme is HTTPS:

Deploy the operation and test it with «Try it out». Enter the previously retrieved token and the parameter you want to filter by, and execute:

If you click on «Execute», you will obtain the result of the programmed query in the API when «param = 10».

With this, we have finished this workshop on the Platform. We hope that it has been of your interest, and do not hesitate to comment on your doubts and impressions.

✍🏻 Author(s)

Leave a Reply