Procedures as REST: Example of getting data

Official Content

The following example shows a REST GeneXus procedure that returns information about a Customer, given its Identification.

The GeneXus procedure (called "GetCustomer") is declared as REST by setting the following properties:

  • Expose as web service = True
  • Rest Protocol = True


The code is very simple, as shown below:

Parm Rule:


Source Code:

for each
 where CustomerId = &CustomerId
 &customerName = CustomerName
 &CustomerBirthDate = CustomerBirthDate
 &CustomerPayDate = CustomerPayDate

The GeneXus client can be as follows:

&httpclient.Host =&host // &httpclient is an HTTPClient variable data type
&httpclient.Port = &port
&httpclient.BaseUrl = &baseurl //Example: /webappname/rest/
&customersdt.CustomerId= &customerId
&body = &customersdt.ToJson()
 &lvc = &httpclient.ToString() 

Since the response is in Json format:


the result should be processed using , loading the Json response in an SDT (Structure SDT Object) with the corresponding structure.


  • The Json code (in the example, the variable &body) must include only the items declared as parameters in the parm rule.
  • The values in the Json code have to be CamelCase as defined in the parm rule of the REST procedure.

How do we call a REST procedure object from a general REST client?

In general, we set the following:

URL http://localhost:8080/applicationname/rest/GetCustomer
Body parameter Content-Type: application/json; charset=UTF-8
Method Post



Based on the previous sample calling a 'GetCustomer' object, a sample request is as follows:

POST /Demo20140425U4JavaScriptEnvironment1/rest/GetCustomer HTTP/1.1
Content-Length: 17
Content-Type: application/json; charset=UTF-8
Host: localhost:8181
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.3.1 (java 1.5)

And the response is as follows:

HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Set-Cookie: JSESSIONID=D737067FECD79CD466F29877D3B74375; Path=/Demo20140425U4JavaScriptEnvironment1/; HttpOnly
Last-Modified: Wed, 23 Jul 2014 06:29:04 GMT
Content-Type: application/json;charset=UTF-8
Transfer-Encoding: chunked
Date: Wed, 23 Jul 2014 06:29:05 GMT


See Also

Rest web services in GeneXus

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