Official 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:

1. How are the Rest services called in GeneXus?

Use the HttpClient data type.

2. Which HTTP method is used to call the Rest Data Provider?

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

3. Which is the URL format to execute the GET verb?

<ServerUrl>/<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 &.

Samples

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

i2016_03_31_19_53_291_png

A DP (called "DPCaso20") has been created, whose Data Provider Output is the Invoice BC. Also, it's exposed as a Rest service as shown below:

i2016_03_31_19_54_552_png

The DP has the following rule:

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

The following code is used to call that Rest DP:

//http://server:8080/BaseUrl/rest/DPCaso20?Invoicedate=2013-11-14&Customerid=1&Customername=Francisco
&httpclient.Host= "server"
&httpclient.Port = 8080
&httpclient.BaseUrl = "BaseUrl"
&httpclient.secure = 0
&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

Notes:

  • If the service URI is http://localhost/TestRESTFullGX.NetEnvironment/rest/Invoice, the BASE URL is: /TestRESTFullGX.NetEnvironment/rest/
  • In Java, the parameter 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: GeneXus provides the OpenAPI import tool for consuming a Rest service, whether it's been generated by GeneXus or not.


Last update: February 2024 | © GeneXus. All rights reserved. GeneXus Powered by Globant