AI Skill Report Card
Generating TypeScript API Controllers
TypeScript API Controller Generator
Quick Start15 / 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
Workflow13 / 15
-
Gather Requirements
- API endpoint pattern
- HTTP method (GET, POST, PUT, DELETE)
- Path parameters (0-M)
- Query string parameters type
- Response data type
-
Define Function Signature
- Path parameters first (in order they appear in URL)
- Query string params object last
- Return type:
Promise<AxiosResponse<ResponseType, any>>
-
Build URL with Parameters
- Use template literals for path params
- Pass query strings via
paramsoption
-
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
Examples18 / 20
Example 1: No path params Input: GET /api/products with ProductQueryParams and Product[] response Output:
TypeScriptexport 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:
TypeScriptexport 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:
TypeScriptexport 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
Best Practices
- Consistent naming: Use
{resource}Controllerpattern - 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
Common Pitfalls
- 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