Official Content

Specifies the method of a declared service in an API object.

Syntax

'['RestMethod(<Method>)']'

View Syntax conventions

Where:

Method
         HTTP method indicating the operation to perform.

Description

The method of a service is GET by default. If you don't want to use GET, you can use this annotation to specify the method that will provide the service.

Sample

Enter a new customer.
Consider the following Transaction defined as a Business Component:

Customer
{
     CustomerId*     (Autonumber property = Yes)
     CustomerName
     CustomerLastName
}

Create a Procedure called InsertOneCustomer and define the following:

Variables:

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

Rules:

Parm(in:&CustomerId, in:&CustomerName, in:&CustomerLastName, out:&Messages);

Source:

&Customer.CustomerId = &CustomerId
&Customer.CustomerName = &CustomerName
&Customer.CustomerLastName = &CustomerLastName

if &Customer.Insert()
   commit
Else
   rollback
Endif
&Messages = &Customer.GetMessages()

Create an API Object called APICustomer and define the following:

Variables:

&CustomerId         (Type:Attribute:CustomerId)
&CustomerName       (Type:Attribute:CustomerName)
&CustomerLastName   (Type:Attribute:CustomerLastName)
&Messages           (Type: Messages, GeneXus.Common)

Service Source:

Customer
{
     [RestMethod(POST)]
     InsertCustomer(in:&CustomerId, in:&CustomerName, in:&CustomerLastName, out:&Messages) =>InsertOneCustomer(&CustomerId,&CustomerName, &CustomerLastName, &Messages);
}

Notes:

  • The RestMethod annotation can be combined with the RestPath annotation; for example: [RestMethod(PUT),RestPath ("/Customer/{&CustomerId}/{&CustomerName}")].

  • The RestMethod annotation must be written immediately before the service declaration.

Availability

Since GeneXus 17 Upgrade 9.


Last update: February 2024 | © GeneXus. All rights reserved. GeneXus Powered by Globant