Official Content

Customizes the path of a service declared in API object.



View Syntax conventions

Note: The number of SubPaths and variables may vary as necessary and they may be interspersed..


SubPath1,..., SubPathN
     Are part of the path to access the service. They are automatically added after the Service base path.

&var1,..., &varN
    Are optional variables defined within the API object, which must be parameters in the service defined with the in operator.


The path of a service includes, in a predetermined manner, the Services base path followed by the name of the service. This annotation allows you to customize the path and to even include the in parameters within it.

By default, the Services base path property has the name assigned to the API object during its definition, as shown below:


That means that, for this example, when you execute the API object, the default path to access the service is:


With RestPath you can customize the service’s path. For instance, to change it from ListCustomers to Customers:


To achieve this, you add [RestPath("/Customers”)] before the service definition.


1. Obtain a list of clients.

Consider the following Transaction:

    CustomerId*                  (Autonumber property = Yes)

Create an Structured Data Type (SDT) object with the name SDTCustomer. Drag the Customer Transaction from the KB Explorer to the SDT Structure. Define the SDT to be a collection by clicking the checkbox Is Collection. Substitute the name SDTCustomersItem with Customer:


Create a Data Provider object called DPCustomerList and fill out as shown below:


After dragging the SDT to the Data Provider Source, the Output property will automatically be configured with the SDTCustomer value.

Create an API object called APICustomer and define the following:


SDTCustomer    (Type:SDTCustomer)

Service Source:

     ListCustomers(out:&SDTCustomer) => DPCustomerList(&SDTCustomer);

The DPCustomerList object is published as a service called ListCustomers.

And last, if you want to expose the service with the OpenAPI format, you need to set in the API object the Generate OpenAPI interface property to Yes.

Upon executing the API object, you will see the following:


2. Obtain information about a client.

Now consider the same Customer Transaction of the previous example and define it as Business Component.

Then, create a Procedure object called ReturnOneCustomerData, with the following definition:


&Customer          (Type: Customer)
&CustomerId        (Type:Attribute:CustomerId)


​​Parm(in:&CustomerId, out:&Customer);


if &Customer.Fail()
     &Customer.CustomerId = 0
     &Customer.CustomerLastName = "Invalid Customer"

Note: Keep in mind that CustomerId has its Autonumber property = Yes.

This Procedure receives a customer’s Id and then accesses the database using the Load method to then return the information that corresponds to the customer required. When no information is found, the customer Id is assigned and returned with value 0 and the client name with "Invalid Customer".

Then, create an API object (called, for example, APICustomer), and define:


&Customer                       (Type: Customer)
&CustomerId                     (Type: Attribute:CustomerId)
&Message                        (Type: Messages.Message, GeneXus.Common)
&Messages                       (Type: Messages, GeneXus.Common)

Service Source:

      GetCustomer(in:&CustomerId, out:&Customer, out:&Messages) => ReturnOneCustomerData(&CustomerId, &Customer);

The ReturnOneCustomerData Procedure is published as a service called GetCustomer.


Event GetCustomer.Before
      if &CustomerId < 0
         &RestCode = 412

Event GetCustomer.After
      if &Customer.CustomerId = 0
         &Message.Type = MessageTypes.Error
         &Message.Description = format("Customer %1 not found", &CustomerId)
         &RestCode = 404

The trigger event GetCustomer.Before verifies if the Id entered is less than zero. In this case, the ReturnOneCustomerData procedure is not executed, returning error 412 (access to the destination resource denied).

Additionally, the GetCustomer.After event returns the error and description following the execution of the ReturnOneCustomerData procedure and obtaining Id 0. Otherwise, it shows the data of the customer entered, on screen.

And last, if you want to expose the service with the OpenAPI format, you need to set in the API object the Generate OpenAPI interface property to Yes.

Upon executing the API object, you will see the following:


If you want, you can add another variable to RestPaht. For example, you can add CustomerName:

      GetCustomer(in:&CustomerId, in:&CustomerName, out:&Customer, out:&Messages) => ReturnOneCustomerData(&CustomerId, &CustomerName, &Customer);


  • The annotation ResPath may be combined, for example, with the annotation RestMethod:  [RestMethod(GET),RestPath("/Customer/{&CustomerId}/{&CustomerName}")]
  • The RestPath annotation affects the service directly below it.


Since GeneXus 17 Upgrade 9.

Last update: November 2023 | © GeneXus. All rights reserved. GeneXus Powered by Globant