The following is a simple example where we consume a procedure exposed as a Rest web service, which only receives simple parameters and doesn't return any.
In the example, the "AddCustomer" Procedure is declared as REST web service in GeneXus, so the following properties are set as described here:
- Expose as web service = true
- Rest protocol = true
The procedure receives "in" parameters in order to add a Customer to the corresponding table:
CustomerId = &CustomerId
CustomerName = &CustomerName
CustomerBirthDate = &CustomerBirthDate
In order to call AddCustomer as a REST web service, you should use HttpClient data type. A GeneXus client should look as shown below:
&httpclient.Port = &port
&httpclient.BaseUrl = &baseurl
&body = &customersdt.ToJson() //&customersdt is a variable of CustomerSdt data type which is an SDT that includes the CustomerId, CustomerName and CustomerBirthDate items.
//Then process the HttpClient response.
Download the sample from Sample consuming a Rest procedure
As shown in the example, the parameters are sent in Json format in the body of the HttpRequest; that's why in the example we use the method to convert the data contained in an SDT to Json format.
With respect to consuming a Rest service (it can be generated by GeneXus or not), GeneXus provides the OpenAPI import tool.
Next, read Procedures as REST: Using SDT as input to the procedure
Rest web services in GeneXus