Working with REST apis

Hi erveryone,

We are currently in the process of rolling SDL WorldServer out in our organisation. We are running our tests on v. 11.0 but will probably go live with 11.1 as soon as it is available.

I am thinking of using the REST API to access some data. However, I am quite new to REST APIs in general. I am able to set up the connection to the server but it stops there. I am not sure how I should proceed to read the response and retrieve the sessionID. The response looks like formatted HTML and not really like JSON content.

The current documentation of the API does not provide samples on how to implement the API. I wanted to ask if some of you maybe have samples or code parts they would agree to share with me. it would be a great help. Code can be in c# or even javascript.

Thanks in advance to those who will reply.

Regards,

Laurent

Parents
  • Hi Laurent,

    I took a look at the link you attached, the API return a Json object, maybe you are not deserializing it  correctly.

    Here you can find a sample application with an example how to make a API call and how to deserialize an JSON object.:

     https://www.dropbox.com/s/h5evpr5cb0ud57r/ApiConnection.zip?dl=0 


    I used JSON.Net library to deserialize the object, you can download from NuGet Packages, also I used a link for a public API (https://github.com/thm/uinames/blob/master/README.md ).

    The ideea is that you must have in your application an object model which has the same properties as the API objects.

    For example on the api documentation you sent to us look at:  /info -> click on GET on the Response tab you should see the model of the object the API sends to you.

    In your application you should have a class named for example Info and has the following properties, this will be your model for INFO object:

     public string CurrentVersion { get; set; }

     public string MinSupportedVersion{ get; set; }

     public string MaxSupportedVersion{ get; set; }

     public string ServerVersion{ get; set; }

     public string DataBase{ get; set; }

    You'll deserialize your object after you call the API like this : Info info = JsonConvert.DeserializeObject<Info>(response);

    Here you can find the documentation for Json.net library : http://www.newtonsoft.com/json/help/html/SerializeObject.htm 

    I hope this will help you.

    Regards,

    Andrea.

Reply
  • Hi Laurent,

    I took a look at the link you attached, the API return a Json object, maybe you are not deserializing it  correctly.

    Here you can find a sample application with an example how to make a API call and how to deserialize an JSON object.:

     https://www.dropbox.com/s/h5evpr5cb0ud57r/ApiConnection.zip?dl=0 


    I used JSON.Net library to deserialize the object, you can download from NuGet Packages, also I used a link for a public API (https://github.com/thm/uinames/blob/master/README.md ).

    The ideea is that you must have in your application an object model which has the same properties as the API objects.

    For example on the api documentation you sent to us look at:  /info -> click on GET on the Response tab you should see the model of the object the API sends to you.

    In your application you should have a class named for example Info and has the following properties, this will be your model for INFO object:

     public string CurrentVersion { get; set; }

     public string MinSupportedVersion{ get; set; }

     public string MaxSupportedVersion{ get; set; }

     public string ServerVersion{ get; set; }

     public string DataBase{ get; set; }

    You'll deserialize your object after you call the API like this : Info info = JsonConvert.DeserializeObject<Info>(response);

    Here you can find the documentation for Json.net library : http://www.newtonsoft.com/json/help/html/SerializeObject.htm 

    I hope this will help you.

    Regards,

    Andrea.

Children
No Data