$npx -y skills add totvs/engpro-advpl-tlpp-skills --skill tlpp-rest-endpoint-generatorGenerate 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', '
| 1 | # TLPP REST Endpoint Generator |
| 2 | |
| 3 | ## Overview |
| 4 | |
| 5 | 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. |
| 6 | |
| 7 | ## When to Use |
| 8 | |
| 9 | Use this skill when: |
| 10 | |
| 11 | - Creating new REST API endpoints in TLPP |
| 12 | - Implementing TOTVS TTALK-compliant APIs |
| 13 | - Generating CRUD endpoints for Protheus entities |
| 14 | - Building integration APIs for external systems |
| 15 | - Migrating WsRESTful services to TLPP REST |
| 16 | |
| 17 | --- |
| 18 | |
| 19 | ## TLPP REST Architecture |
| 20 | |
| 21 | ### How It Works |
| 22 | |
| 23 | 1. A function is annotated with an HTTP verb annotation (e.g., `@Get("/path")`) |
| 24 | 2. The TLPP REST Server automatically registers the route at startup via annotation scanning |
| 25 | 3. When a request matches the route, the annotated function is invoked |
| 26 | 4. The function uses the global `oRest` object to read the request and write the response |
| 27 | 5. Swagger/OpenAPI documentation is generated automatically from the annotations |
| 28 | |
| 29 | ### Available Annotations |
| 30 | |
| 31 | | Annotation | HTTP Verb | Typical Use | |
| 32 | | --------------------- | --------- | ---------------------------- | |
| 33 | | `@Get("endpoint")` | GET | Retrieve resource(s) | |
| 34 | | `@Post("endpoint")` | POST | Create a new resource | |
| 35 | | `@Put("endpoint")` | PUT | Full update of a resource | |
| 36 | | `@Patch("endpoint")` | PATCH | Partial update of a resource | |
| 37 | | `@Delete("endpoint")` | DELETE | Remove a resource | |
| 38 | |
| 39 | **Annotation properties:** |
| 40 | |
| 41 | - `endpoint` (required): The URI path for the route |
| 42 | - `description` (optional): Description shown in Swagger docs |
| 43 | |
| 44 | ```tlpp |
| 45 | // Minimal form (endpoint only) |
| 46 | @Get("/api/v1/customers") |
| 47 | |
| 48 | // Full form (named properties) |
| 49 | @Get(endpoint="/api/v1/customers", description="List all customers") |
| 50 | ``` |
| 51 | |
| 52 | --- |
| 53 | |
| 54 | ## The oRest Object |
| 55 | |
| 56 | The `oRest` object is a global object available inside any annotated REST function. It provides all methods for reading requests and writing responses. |
| 57 | |
| 58 | ### Request Methods |
| 59 | |
| 60 | | Method | Returns | Description | |
| 61 | | ------------------------------ | --------- | -------------------------------------- | |
| 62 | | `oRest:getQueryRequest()` | Json | Query string parameters (`?key=value`) | |
| 63 | | `oRest:getBodyRequest()` | Character | Raw request body as string | |
| 64 | | `oRest:getPathParamsRequest()` | Json | Path parameters (e.g., `:id`) | |
| 65 | | `oRest:getHeaderRequest()` | Json | All request headers | |
| 66 | | `oRest:getClientIP()` | Character | Client IP address | |
| 67 | |
| 68 | ### Response Methods |
| 69 | |
| 70 | | Method | Parameters | Description | |
| 71 | | --------------------------------------------- | -------------------- | --------------------------------------------------------- | |
| 72 | | `oRest:setResponse(cBody)` | Character | Set response body (concatenates if called multiple times) | |
| 73 | | `oRest:setStatusResponse(nCode, cBody)` | Numeric, Character | Set HTTP status code and body; returns Logical | |
| 74 | | `oRest:setKeyHeaderResponse(cKey, cValue)` | Character, Character | Set a response header | |
| 75 | | `oRest:updateKeyHeaderResponse(cKey, cValue)` | Character, Character | Update an existing response header | |
| 76 | | `oRest:resetResponse()` | — | Clear the response body | |
| 77 | | `oRest:getBodyResponse()` | — | Get current response body | |
| 78 | |
| 79 | ### Path Parameters |
| 80 | |
| 81 | Use `:paramName` syntax in the endpoint path to define path parameters: |
| 82 | |
| 83 | ```tlpp |
| 84 | @Get("/api/v1/customers/:id") |
| 85 | User Function getCustomer() as Logical |
| 86 | Local jPathParams := oRest:getPathParamsRequest() as Json |
| 87 | Local cId := jPathParams["id"] as Character |
| 88 | // ... |
| 89 | Return oRest:setStatusResponse(200, cResponse) |
| 90 | ``` |
| 91 | |
| 92 | --- |
| 93 | |
| 94 | ## Bundled Reference Files |
| 95 | |
| 96 | 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 |