AI Skill Report Card

Generating TypeScript API Controllers

B+78·May 6, 2026·Source: Web

TypeScript API Controller Generator

15 / 15
TypeScript
// Basic GET controller with path params and query strings export const getUsersController = async ( organizationId: string, qsParams: User.QueryParams, ): Promise<AxiosResponse<App.Pagination<User.User>, any>> => { const url = `/api/organizations/${organizationId}/users/`; const instance = genRequestInstance(); try { const response = await instance.get(url, { params: qsParams }); return response; } catch (error) { console.error('Erro na requisição:', error); return Promise.reject(error); } };
Recommendation
Add concrete input/output examples showing the actual API endpoint specification and resulting function name/signature
13 / 15
  1. Gather Requirements

    • API endpoint pattern
    • HTTP method (GET, POST, PUT, DELETE)
    • Path parameters (0-M)
    • Query string parameters type
    • Response data type
  2. Define Function Signature

    • Path parameters first (in order they appear in URL)
    • Query string params object last
    • Return type: Promise<AxiosResponse<ResponseType, any>>
  3. Build URL with Parameters

    • Use template literals for path params
    • Pass query strings via params option
  4. Add Error Handling

    • Try/catch block
    • Console error logging
    • Promise rejection
Recommendation
Include templates for PUT/PATCH/DELETE methods beyond just GET and POST examples
18 / 20

Example 1: No path params Input: GET /api/products with ProductQueryParams and Product[] response Output:

TypeScript
export const getProductsController = async ( qsParams: Product.QueryParams, ): Promise<AxiosResponse<Product.Product[], any>> => { const url = `/api/products/`; const instance = genRequestInstance(); try { const response = await instance.get(url, { params: qsParams }); return response; } catch (error) { console.error('Erro na requisição:', error); return Promise.reject(error); } };

Example 2: Multiple path params Input: GET /api/companies/{companyId}/departments/{deptId}/employees Output:

TypeScript
export const getEmployeesController = async ( companyId: string, deptId: string, qsParams: Employee.QueryParams, ): Promise<AxiosResponse<App.Pagination<Employee.Employee>, any>> => { const url = `/api/companies/${companyId}/departments/${deptId}/employees/`; const instance = genRequestInstance(); try { const response = await instance.get(url, { params: qsParams }); return response; } catch (error) { console.error('Erro na requisição:', error); return Promise.reject(error); } };

Example 3: POST with body Input: POST /api/orders with CreateOrderData body Output:

TypeScript
export const createOrderController = async ( data: Order.CreateOrderData, qsParams?: Order.CreateQueryParams, ): Promise<AxiosResponse<Order.Order, any>> => { const url = `/api/orders/`; const instance = genRequestInstance(); try { const response = await instance.post(url, data, { params: qsParams }); return response; } catch (error) { console.error('Erro na requisição:', error); return Promise.reject(error); } };
Recommendation
Add guidance on handling different response types (arrays vs single objects vs paginated responses) more systematically
  • Consistent naming: Use {resource}Controller pattern
  • Path params first: Order parameters by URL appearance
  • Optional query params: Use ? for optional query string parameters
  • Trailing slashes: Include trailing slash in URLs for consistency
  • Generic error handling: Keep error handling simple and consistent
  • Type safety: Always provide proper TypeScript types for params and responses
  • Wrong parameter order: Path parameters must match URL order
  • Missing error handling: Always wrap in try/catch
  • Inconsistent URL patterns: Maintain consistent trailing slash usage
  • Overly complex typing: Keep response types simple with AxiosResponse wrapper
  • Missing async/await: Always use async/await pattern for consistency
0
Grade B+AI Skill Framework
Scorecard
Criteria Breakdown
Quick Start
15/15
Workflow
13/15
Examples
18/20
Completeness
15/20
Format
14/15
Conciseness
13/15