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

1. How is the Rest service called in GeneXus?

Use the HttpClient data type.

2. What are the HTTP methods used 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.

Samples

Suppose you 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, the Invoice whose InvoiceId=1 will be deleted.

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 URI service 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: 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