HowTo: Deleting data from a BC exposed as a Rest serviceOfficial Content

This document explains how to delete data using a Business Component 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.

What are the HTTP methods to delete data?

Delete the data using the HTTP DELETE verb. The PK values have to be added to the query string when the HTTP DELETE verb is executed.

Example

Consider the following example, where we want to delete an Invoice record (which is a two-level transaction). Note that the BC is exposed as a Rest Service.

i2016_03_30_18_04_151_png

Here we are going to delete the Invoice whose InvoiceId=1.

Sample Code

&httpclient.Host= &server
&httpclient.Port = &port
&httpclient.BaseUrl = &urlbase
&httpclient.Execute('DELETE','Invoice/1')

if &httpclient.StatusCode = 200
    &result = &httpclient.ToString()
else
   msg("There was an error deleting the data: " + &httpclient.StatusCode.ToString())
endif

Download the sample from Sample Delete Rest BC

Notes:

  • If more than one parameter should be passed in the URL (a compound PK), they need to be separated by commas.
  • If the service URI is "http://localhost/TestRESTFullGX.NetEnvironment/rest/Product", the BASE URL is: "/TestRESTFullGX.NetEnvironment/rest/"
  • Error handling is managed by querying the HTTP Status Code after the invocation.

See Also

Business Components as 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.