Configuração Rest TLPP
Configuração Rest TLPP
Configuração Rest TLPP
Tdn:
https://tdn.totvs.com/pages/viewpage.action?pageId=553334690
Configuração do .ini:
;
;Configuracao REST
;
[HTTPSERVER]
Enable=1
Servers=HTTP_REST
[HTTP_REST]
hostname=localhost
port=9995
locations=HTTP_ROOT
[HTTP_ROOT]
Path=/
RootPath=D:\TOTVS\TOTVS 12\Microsiga\protheus_data\web\rest
DefaultPage=index.html
ThreadPool=THREAD_POOL
[THREAD_POOL]
Environment=TREINAMENTO
MinThreads=1
MaxThreads=4
GrowthFactor=1
InactiveTimeout=30000
AcceptTimeout=10000
/*/{Protheus.doc} RESTTLPPDEMO
Treinamento desenvolvimento Rest em TLPP
@type Rest TLPP
@author Dataroute
@since 08/12/2022
/*/
@get("dataroute/clientes")
user function getListCliente()
local body := JsonObject():new() as Object
local oClient := JsonObject():new() as Object
local oListClient := JsonObject():new() as Object
local oParams := JsonObject():new() as Object
local aDados := {} as Array
local cQuery := " " as Character
local jHeader
local jQueryString
local cCodCli := "" as Character
RPCSetEnv("01","0101001")
//Define a resposta em formato Json
oRest:setKeyHeaderResponse('Content-Type','application/json')
varinfo("body",body)
varinfo("jHeader",jHeader)
varinfo("jQueryString",jQueryString)
dbUseArea(.T.,"TOPCONN",TCGenQry(,,cQuery),"QTMPSA1",.T.,.T.)
DbSelectArea("QTMPSA1"); QTMPSA1->(DBGOTOP())
while QTMPSA1->(!eof())
oClient := JsonObject():new()
oClient["codigo"] := QTMPSA1->A1_COD
oClient["nome"] := alltrim(QTMPSA1->A1_NOME)
aAdd(aDados,oClient)
QTMPSA1->(dbSkip())
enddo
DbSelectArea("QTMPSA1");dbcloseArea()
return
@Post("dataroute/clientes")
user function postCliente()
local body := JsonObject():new() as Object
oRest:setResponse( '{"sample":"format"}' )
return
Testando no Postman:
Informando CodCliente
Sem CodCliente: