The use of APIs allows us to access a set of functions and methods that we would otherwise have to develop ourselves, which would cost time. In the case of the Apicultur APIs, we rely on a number of methods, all of which are linguistic, that make our lives easier in this field.

However, the lack of knowledge sometimes makes it difficult to use a particular resource, and a hand-made example makes life easier. Anyway, without further ado, let’s explain how we can access the Apicultur APIs, collect data and use them with C# and Visual Studio 2012.

Let’s go!

We have done a little project that we’ve called Cruzaletras, which consists of a small application that allows us to obtain combinations for our games of Scrabble, Intelect and Crosswords…using the ApiculturSubPalabras v.1.0.0 API.

Using XAML or the blend, we have created a “TextBox” (x:Name=”letters”) in order to add the word we want to search for, a “Button” (x:Name=”submit”) in order to send the search and a un “TextBlock” (x:Name=”results”) in order to show the results.

imagen_post_1

Once the design is created we can continue. First of all, you need an API Key from Apicultur, both for testing and for final usage. To do this you can go to “1. Creation of a new Apicultur account and subscription” at the beginning Improve your database search results with Apicultur, where it explains clearly and concisely how to obtain it.

Once this is done and once you have our “Production Access Token” we can continue.

Our program has 4 functions:

1.- StartWebRequest: Create an HttpWebRequest and collect the data, calling FinishWebRequest in order to process them.

Captura de pantalla 2013-06-14 a las 21.07.292.- FinishWebRequest: Collect the data that the API sends and process it through a call to the ReadToWord method.

Captura de pantalla 2013-06-14 a las 21.10.273.- ReadToWord: It will convert the collected JSON into a Word-type document. In this case it will become a list of Word-type documents.

Captura de pantalla 2013-06-14 a las 21.14.05

4.- submit_Tap: And finally we have to call the StartWebRequest function. The function will be called when you press the “submit” button.

Captura de pantalla 2013-06-14 a las 21.21.16

In our case we have also created a Word class in order to process the JSON, it’s not necessary but recommended.

Captura de pantalla 2013-06-14 a las 21.25.52

And that’s all. We can write a word in the TextBox, click OK and in a few moments we will have our results.

Captura de pantalla 2013-06-14 a las 21.28.59

Author: Javi Barrera, Winner of the Iberic APIdays Mediterranea Hackathon (Categoría APIcultur)
Share →