Consuming REST Data Providers in Genexus

Let's suppose that we need to consume the following REST web service in our GeneXus application:

http://labs.genexus.com/mobilecrm/rest/WorkWithDevicesCompany_Company_List_Grid?fmt=json

where its response is in JSON format and looks as follows:

[{"CompanyId":"1","CompanyLogo":"PublicTempStorage\/image\/gx_upl_a7473480b990012f68a412313d236401.tmp","CompanyName":"Adobe"},

{"CompanyId":"14","CompanyLogo":"PublicTempStorage\/image\/gx_upl_f38b1930f3ff012fc28e12313d236401.tmp","CompanyName":"Apple"}]

To consume it in GeneXus:

1. Define a Structured Data Type as follows:

SDTCompany

2. Write the following code in your GeneXus object (use HttpClient data type):

&httpclient.Host = "labs.genexus.com"
&httpclient.BaseUrl = "/mobilecrm/rest/"
&httpclient.Execute('GET','WorkWithDevicesCompany_Company_List_Grid?fmt=json')
&companies.FromJson(&httpclient.ToString() )

where:

&htttpclient is a HttpClient data type variable and

&companies is a collection variable based on the Structured Data Type defined previously.

3. Finished! you already have your companies loaded in your &companies variable

See Also

Rest web services in GeneXus