← ClaudeAtlas

create-api-providerlisted

Add a Retrofit @RestApi provider in packages/api — the _Paths convention, method annotations, request bodies, queries, multipart, barrel exports, DioService registration and interceptors. Use when adding a new API resource or a new endpoint to an existing one.
NarekManukyan/flutter-mobx-kit · ★ 0 · API & Backend · score 70
Install: claude install-skill NarekManukyan/flutter-mobx-kit
# Create a Retrofit API provider Governed by [ADR-0011](../../../docs/adr/0011-retrofit-typed-api-layer.md). Providers live in `packages/api`; app code reaches them only through `DioService`. ## Shape One provider per resource, at `packages/api/lib/src/providers/{resource}_provider/{resource}_api_provider.dart`. ```dart import 'package:dio/dio.dart'; import 'package:retrofit/retrofit.dart'; import 'models/models.dart'; part 'todos_api_provider.g.dart'; class _Paths { static const getTodos = '/todos'; static const createTodo = '/todos'; static const todoById = '/todos/{id}'; _Paths._(); } @RestApi() abstract class TodosApiProvider { factory TodosApiProvider(Dio dio) = _TodosApiProvider; @GET(_Paths.getTodos) Future<List<TodoDto>> getTodos(); @POST(_Paths.createTodo) Future<TodoDto> createTodo({ @Body() required TodoCreateRequestDto todoCreateDto, }); @DELETE(_Paths.todoById) Future<void> deleteTodo(@Path('id') String id); } ``` - **Every path string goes in the private `_Paths` class** with a private constructor. No literals in annotations. - The `factory … = _{Name}` line is required — it binds to the generated implementation. - Method names are verbs: `getTodos`, `createTodo`, `deleteTodo`. ## Return types - Single resource → the DTO directly: `Future<TodoDto>`. - Paginated list → the shared envelope: `Future<ListResponseDto<TodoDto>>`. - Unwrapped list → `Future<List<TodoDto>>` only when the server really returns a bare array. - No