@Get/@Post
Decorators TLPP que expoem funcoes como endpoints REST automaticamente. Substitui WS_DEFINITION/WSMETHOD do AdvPL antigo.
Assinatura: @Get('/path') | @Post('/path') | @Put | @Delete
Retorna: construct
Decorators @Get, @Post, @Put, @Delete declaram que uma funcao TLPP e um endpoint REST. O AppServer roteia automaticamente pelo path — nao precisa configurar nada no appserver.ini alem do HTTPV11.
Sintaxe basica
#include 'tlpp-core.th'
#include 'tlpp-rest.th'
namespace archtec.api
@Get('/clientes')
function ListarClientes()
local aClientes as array
aClientes := CarregaClientes()
httpResponse:setContentType('application/json')
httpResponse:setBody(jsonObject():new():fromArray(aClientes):toJson())
returnGET com parametro de URL
@Get('/clientes/{id}')
function GetCliente()
local cId as character
local oJson as object
cId := httpRequest:getURLParam('id')
oJson := JsonObject():new()
oJson['id'] := cId
oJson['nome'] := 'Cliente ' + cId
httpResponse:setContentType('application/json')
httpResponse:setBody(oJson:toJson())
returnPOST com body
@Post('/clientes')
function CriarCliente()
local cBody as character
local oReq as object
cBody := httpRequest:getBody()
oReq := JsonObject():new()
oReq:fromJson(cBody)
// ... validar e gravar ...
httpResponse:setStatus(201)
httpResponse:setBody('{"created":true}')
returnMultiplos metodos
@Get('/health')
@Post('/health')
function Health()
httpResponse:setBody('{"status":"ok"}')
returnPegadinhas
- HTTPV11 precisa estar habilitado no AppServer (porta separada)
- Authorization nao e automatico — implementar manual checando
httpRequest:getHeader('Authorization') - CORS: setar manualmente nos headers se for chamado de browser
Exemplos
Endpoint REST minimo
@Get('/ping')
function Ping()
httpResponse:setBody('pong')
return