HowTo: Consuming a Rest Data ProviderOfficial Content

This document explains how to call a Data Provider (DP) exposed as Rest web services in GeneXus.

First, let's see the basic guidelines:

How do I call the Rest service in GeneXus?

Use the HttpClient data type.

Which HTTP method should I use to call the Rest Data Provider?

The HTTP method used for calling the Data Provider is the HTTP GET verb.

Which is the URL format to execute the GET verb?

<server uri>/rest/<module>/<DP name>?param1=value1&param2=value2,..,paramN=valueN

Where <param1>,<param2>,..,<paramN> are the parameters of the DP. The parameters should be separated by &.

Example

Consider the Invoice Business Component transaction, which looks as follows:

i2016_03_31_19_53_291_png

We have created a DP (called "DPCaso20"), whose Data Provider: Output is the Invoice BC. Also, it's exposed as a Rest service. See the figure below:

i2016_03_31_19_54_552_png

The DP has the following rule:

parm(in:&invoicedate,in:&CustomerId, in:&Customername);

To call that Rest DP, we have the following code:

&httpclient.Host= &server
&httpclient.Port = &port
&httpclient.BaseUrl = &urlbase
&httpclient.Execute('GET','DPCaso20?invoicedate=2013-11-14&CustomerId=1&Customername=Francisco')

if &httpclient.StatusCode = 200
    &result = &httpclient.ToString()
else
   msg("Error: " + &httpclient.StatusCode.ToString())
endif

Download the sample from Sample consuming a Rest DP

Note

  • If the service URI is "http://localhost/TestRESTFullGX.NetEnvironment/rest/Invoice", the BASE URL is: "/TestRESTFullGX.NetEnvironment/rest/"
  • The parameters name must be normalized (First Character must be uppercase, and all the others must be lowercase) , in this example: Invoicedate, Customerid and Customername. 
  • Error handling is managed by querying the HTTP Status Code after the invocation.

See Also

Rest web services in GeneXus


 

Note:
With respect to consuming a Rest service (it can be generated by GeneXus or not), GeneXus provides the OpenAPI import tool.




Was this page helpful?
What Is This?
Your feedback about this content is important. Let us know what you think.