AI Skill Report Card

Building TypeScript API Controllers

B+78·May 6, 2026·Source: Web
15 / 15
TypeScript
export const getResourceController = async ( id: string, qsParams: ResourceQueryParams, ): Promise<AxiosResponse<App.Pagination<Resource>, any>> => { const url = `/api/resource/${id}`; 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
Remove the generic 'Builds TypeScript API controller functions' opening and jump straight to the pattern/methodology
12 / 15

Progress:

  • Define function signature with URL parameters first, then query string params
  • Build URL path with required parameters embedded
  • Create request instance
  • Make request with query string as params object
  • Handle errors with console.error and Promise.reject

Step-by-step Process:

  1. Function signature: Required URL params first, then optional query string params
  2. URL construction: Embed required parameters directly in URL path
  3. Query string handling: Always use { params: qsParams } pattern
  4. Error handling: Log error and reject promise
Recommendation
Expand the workflow checklist to include type definitions for QueryParams interfaces and return type patterns
20 / 20

Example 1: With URL parameter

TypeScript
export const getUserPostsController = async ( userId: string, qsParams: PostQueryParams, ): Promise<AxiosResponse<App.Pagination<Post>, any>> => { const url = `/api/user/${userId}/posts`; 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 URL parameters

TypeScript
export const getProjectTasksController = async ( projectId: string, sprintId: string, qsParams: TaskQueryParams, ): Promise<AxiosResponse<App.Pagination<Task>, any>> => { const url = `/api/project/${projectId}/sprint/${sprintId}/tasks`; 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: No URL parameters

TypeScript
export const getAllUsersController = async ( qsParams: UserQueryParams, ): Promise<AxiosResponse<App.Pagination<User>, any>> => { const url = `/api/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 coverage of POST/PUT/DELETE methods and request body handling patterns to make it more complete
  • Always use { params: qsParams } for query strings, never manual concatenation
  • Place required URL parameters before query string parameters in function signature
  • Embed URL parameters directly in the path string using template literals
  • Use consistent error handling pattern with console.error and Promise.reject
  • Return the full AxiosResponse, don't extract data in controller
  • Use descriptive controller function names ending with "Controller"
  • Don't mix URL parameter styles (embedding vs query string)
  • Don't use getQueryStringFromRecord() when { params: qsParams } works
  • Don't modify the error object before rejecting
  • Don't extract response.data in the controller - let the caller handle it
  • Don't forget to await the instance.get() call
0
Grade B+AI Skill Framework
Scorecard
Criteria Breakdown
Quick Start
15/15
Workflow
12/15
Examples
20/20
Completeness
14/20
Format
15/15
Conciseness
12/15