agentleFS
totvstotvs/engpro-advpl-tlpp-skills/skills/advpl-tlpp/tlpp-rest-endpoint-generator/SKILL.md

tlpp-rest-endpoint-generator

Skill138 starsChanged 6 months agoMITView on GitHub

Generate TLPP REST endpoints using annotation-based routing (@Get, @Post, @Put, @Patch, @Delete) with the oRest object. Follows TOTVS API standards (TTALK) including pagination, error model, standard headers, and Swagger documentation. Use when user says 'create REST endpoint', 'TLPP REST', '@Get annotation', 'oRest endpoint'.

The file

We split this skill into the rules it gives an agent

5 rules. About 0 are common, 4 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈4

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use this skill when:

    line 21
  2. Distinctive:

    When a request matches the route, the annotated function is invoked

    line 37
  3. Very specific:

    Use :paramName syntax in the endpoint path to define path parameters:

    line 93
  4. Distinctive:

    Read references/tlpp-rest-endpoint-templates.md for the code templates matching the required verb(s).

    line 132
  5. Distinctive:

    Use the checklist below to verify the generated code covers all requirements.

    line 140

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

TLPP REST Endpoint Generator

Overview

Generate production-ready TLPP REST endpoints using the native annotation-based REST framework. TLPP REST replaces the legacy WsRESTful pattern with a simpler, annotation-driven approach. Each endpoint is a function decorated with an HTTP verb annotation and uses the global oRest object to handle requests and responses.

When to Use

Use this skill when:

  • Creating new REST API endpoints in TLPP
  • Implementing TOTVS TTALK-compliant APIs
  • Generating CRUD endpoints for Protheus entities
  • Building integration APIs for external systems
  • Migrating WsRESTful services to TLPP REST

TLPP REST Architecture

How It Works

  1. A function is annotated with an HTTP verb annotation (e.g., @Get("/path"))
  2. The TLPP REST Server automatically registers the route at startup via annotation scanning
  3. When a request matches the route, the annotated function is invoked
  4. The function uses the global oRest object to read the request and write the response
  5. Swagger/OpenAPI documentation is generated automatically from the annotations

Available Annotations

AnnotationHTTP VerbTypical Use
@Get("endpoint")GETRetrieve resource(s)
@Post("endpoint")POSTCreate a new resource
@Put("endpoint")PUTFull update of a resource
@Patch("endpoint")PATCHPartial update of a resource
@Delete("endpoint")DELETERemove a resource

Annotation properties:

  • endpoint (required): The URI path for the route
  • description (optional): Description shown in Swagger docs
// Minimal form (endpoint only)
@Get("/api/v1/customers")

// Full form (named properties)
@Get(endpoint="/api/v1/customers", description="List all customers")

The oRest Object

The oRest object is a global object available inside any annotated REST function. It provides all methods for reading requests and writing responses.

Request Methods

MethodReturnsDescription
oRest:getQueryRequest()JsonQuery string parameters (?key=value)
oRest:getBodyRequest()CharacterRaw request body as string
oRest:getPathParamsRequest()JsonPath parameters (e.g., :id)
oRest:getHeaderRequest()JsonAll request headers
oRest:getClientIP()CharacterClient IP address

Response Methods

MethodParametersDescription
oRest:setResponse(cBody)CharacterSet response body (concatenates if called multiple times)
oRest:setStatusResponse(nCode, cBody)Numeric, CharacterSet HTTP status code and body; returns Logical
oRest:setKeyHeaderResponse(cKey, cValue)Character, CharacterSet a response header
oRest:updateKeyHeaderResponse(cKey, cValue)Character, CharacterUpdate an existing response header
oRest:resetResponse()—Clear the response body
oRest:getBodyResponse()—Get current response body

Path Parameters

Use :paramName syntax in the endpoint path to define path parameters:

@Get("/api/v1/customers/:id")
User Function getCustomer() as Logical
  Local jPathParams := oRest:getPathParamsRequest() as Json
  Local cId := jPathParams["id"] as Character
  // ...
Return oRest:setStatusResponse(200, cResponse)

Bundled Reference Files

This skill uses progressive disclosure. The SKILL.md body covers the architecture, decision logic, and the generation checklist. Detailed endpoint templates, TTALK standards, and troubleshooting are in the references/ directory — read them on demand based on the scenario:

Reference FileWhen to ReadContent
references/tlpp-rest-endpoint-templates.mdGenerating any CRUD endpoint — GET list (paginated), GET by ID, POST, PUT, or DELETEFull code templates for all 5 HTTP verbs, shared helper functions (BuildErrorResponse, BuildValidationErrorResponse)
references/ttalk-standards-and-configuration.mdChecking TTALK response formats, HTTP status codes, REST server appserver.ini configuration, or debugging endpoint issuesTTALK collection/error JSON formats, pagination query parameters, status code table, appserver.ini REST section, troubleshooting guide

Also refer to references/sonarqube-rules-reference.md for the complete SonarQube rules reference shared across skills.


Endpoint Generation Workflow

Step 1: Gather Requirements

Determine from the user's request:

  • Which HTTP verb(s) to generate (GET, POST, PUT, PATCH, DELETE, or full CRUD)
  • The target Protheus entity/table (e.g., SA1 = Customers, SA2 = Suppliers)
  • The endpoint base path (e.g., /api/v1/customers)
  • Whether TTALK-compliant pagination is needed (collection endpoints)

Step 2: Load Templates

Read references/tlpp-rest-endpoint-templates.md for the code templates matching the required verb(s). Adapt the templates to the target entity by replacing table aliases, field names, and namespace.

Step 3: Apply TTALK Standards

For TOTVS-ecosystem APIs, read references/ttalk-standards-and-configuration.md to ensure responses follow the standard collection format, error model, and HTTP status codes.

Step 4: Validate Against Checklist

Use the checklist below to verify the generated code covers all requirements.


Endpoint Generation Checklist

Structure

  • #include "tlpp-core.th" is the first include
  • Namespace declaration matches project convention
  • User Function name is descriptive and uses camelCase
  • HTTP verb annotation matches the operation semantics
  • Endpoint path follows RESTful conventions (/api/v1/{resource})
  • Path parameters use :paramName syntax

Request Handling

  • Body parsed and validated for POST/PUT/PATCH
  • Path parameters extracted via oRest:getPathParamsRequest()
  • Query parameters extracted via oRest:getQueryRequest()
  • Input sanitized before use in SQL queries (FWExecStatement)

Response

  • Content-Type header set to application/json
  • Correct HTTP status code used
  • Success response follows TTALK format
  • Error response follows TTALK error model
  • Collection endpoints include pagination (hasNext, items, remainingRecords)

Data Access

  • Workarea positioned correctly before read/write
  • Database locks acquired with RecLock() and released with MsUnlock()
  • D_E_L_E_T_ filter always included in queries
  • Branch filter (FWxFilial) always included
  • Temporary aliases closed with DBCloseArea()
  • SQL injection prevented (FWExecStatement)

Error Handling

  • Try-Catch wraps database operations
  • Errors logged with FWLogMsg() including function context
  • Error responses use TTALK error format
  • Lock failures handled gracefully

Security

  • Authentication verified (if applicable)
  • Authorization checked for the operation
  • Input validated against expected types and ranges
  • No sensitive data in error messages

SonarQube Compliance

  • No RpcSetEnv / RpcSetType calls in REST endpoint functions — use REST Server PrepareIn configuration instead
  • No assignment to __cUserID or cEmpAnt — these are protected system variables
  • No StaticCall() — use FWLoadModel(), FWLoadMenuDef(), or namespace-based calls
  • No hardcoded passwords or credentials in source code
  • FWExecStatement used for all queries with dynamic parameters
  • Logging via FWLogMsg(), not ConOut()
  • No IIF() — use If/Else/EndIf blocks
  • GetMV() / ExistBlock() calls moved outside of loops
  • No UI functions (MsgAlert, MsgYesNo, Aviso, Help) inside transaction-scoped handlers
  • Includes in lowercase (e.g., #include "totvs.ch")

Refer to references/sonarqube-rules-reference.md for the complete SonarQube rules reference.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.