rest_client_builder 1.4.0
rest_client_builder: ^1.4.0 copied to clipboard
A Clean Architecture code-generation framework for building typed REST API clients in Dart and Flutter using annotations and build_runner.
Changelog #
All notable changes to this project will be documented in this file.
This project adheres to Semantic Versioning.
1.4.0 #
- Migrated from
intMilliseconds toDuration:- Replaced all raw millisecond
intfields with Dart's idiomaticDurationtype across annotations, configuration, runtime interfaces, and builders. - Annotations:
@ConnectTimeout(Duration(seconds: 10))(was@ConnectTimeout(10000)withmillisecondsproperty).@ReceiveTimeout(Duration(seconds: 30))(was@ReceiveTimeout(30000)withmillisecondsproperty).@SendTimeout(Duration(seconds: 15))(was@SendTimeout(15000)withmillisecondsproperty).@Retry(3, Duration(milliseconds: 200))(wasdelayMs: int).@Cache(duration: Duration(minutes: 5))(wasdurationMs: int).@SSE(reconnectDelay: Duration(seconds: 3))(wasreconnectMs: int).
- Configuration & Runtime Interfaces:
RestClientConfig:connectTimeout,receiveTimeout,sendTimeout,retryDelayare nowDuration.RestApiGlobalConfiguration:connectTimeout,receiveTimeout,sendTimeout,retryDelayare nowDuration?.RestRequest/BasicRestRequest:connectTimeout,receiveTimeout,sendTimeoutare nowDuration?.RestClientBuilder:.timeouts(connectTimeout: ..., receiveTimeout: ..., sendTimeout: ...)and.retry(delay: ...)now acceptDuration.RestResponseCache:put(key, response, Duration duration)now acceptsDuration.SSEEvent:retryfield is nowDuration?parsed automatically from the SSE wire format.
- Generator:
- Updated code generator to read
Durationfrom annotations and emit cleanDurationvalues into generated client code.
- Updated code generator to read
- Replaced all raw millisecond
1.3.7 #
- Restored compatibility with Flutter SDK
meta1.17.0 pin:- Relaxed the
metadependency constraint from^1.19.0to>=1.17.0 <2.0.0. - Flutter stable SDKs (e.g. Flutter 3.38.x) pin
metato1.17.0viaflutter/flutter_test. The previous tight constraint causedpub getto fail for consumers even though the package only uses@Target/TargetKindfrompackage:meta/meta_meta.dart— both of which are fully available sincemeta 1.15.0. - No API changes. No
dependency_overridesrequired by consumers.
- Relaxed the
1.3.6 #
- Documentation & Example Improvements:
- Refined README examples with accurate import/export usage.
- Corrected streaming download result handling using
.when(). - Added documentation for missing
RestResultcombinators (.flatMap(),.mapAsync(),.flatMapAsync(),.getOrElse()). - Added full working examples for
RestClientBuilderand queue management.
- Code Quality:
- Resolved analyzer lints and removed unused generator imports.
- Added missing documentation comments on public generator builder members.
1.3.5 #
- Renamed to
@ResilientQueue(@OfflineQueuepreserved as alias):- Renamed primary annotation to
@ResilientQueueto convey network stability, breakable connection resilience, rate limiting, and server error retries. @OfflineQueueis supported as a backward-compatible typedef alias (typedef OfflineQueue = ResilientQueue;).
- Renamed primary annotation to
- Status Code Trigger Configuration (
enqueueOnStatusCodes):- Added
enqueueOnStatusCodes: List<int>(e.g.[502, 503, 504, 429]) to specify HTTP status codes that automatically trigger queueing inRestQueueInterceptor.
- Added
1.3.4 #
New Features #
-
@SSE— Server-Sent Events Annotation (Stream<SSEEvent>):- Annotate API methods with
@SSEto subscribe to live Server-Sent Event streams (lib/src/annotations/http/sse_annotation.dart). - Spec-compliant HTML §9.2 parser (
SseParser) handlingdata:,event:,id:,retry:, comments (:), and multi-line data concatenation. - Direct
Stream<SSEEvent>return type support withoutFutureorRestResultwrapping. - Runtime execution support in
DioRestClient.executeSSE().
- Annotate API methods with
-
@OfflineQueue— Resilient Offline Request Queueing:- Declarative
@OfflineQueueannotation for auto-queueing failed requests on connection drop, timeout, or 5xx server error (lib/src/annotations/queue/offline_queue_annotation.dart). RestRequestQueuein-memory queue engine with reactive live stream (itemsStream), item list (items), filtering/removal (removeWhere), and flush replay (flush).RestQueueInterceptorfor auto-enqueueing failed requests matching trigger rules.- Custom removal logic support via
RestQueueResolver.
- Declarative
1.3.3 #
New Features #
-
@HTTP— Generic Custom HTTP Verb Annotation (lib/src/annotations/http/http_annotations.dart):
Enables non-standard HTTP verbs beyond the built-in shortcuts (@GET,@POST, etc.).
Supports WebDAV (REPORT,COPY,MOVE,LOCK), CDN (PURGE), and any custom protocol verb.
The method string is automatically uppercased.@HTTP('REPORT', '/analytics') Future<RestResult<Map<String, dynamic>>> report(@Body() Map<String, dynamic> q); -
@Streaming— Streaming Response Annotation (lib/src/annotations/http/streaming_annotation.dart):
Marks a method to receive the HTTP response body as a rawStream<List<int>>without loading it into RAM.
Backed by Dio'sResponseType.streamunder the hood.
Return type must beFuture<RestResult<Stream<List<int>>>>.
Compile-time error if combined with@Multipartor@FormUrlEncoded.@Streaming() @GET('/files/{id}') Future<RestResult<Stream<List<int>>>> downloadFile(@Path('id') String id); -
RestResponseMapper.mapStream(): New static mapper that extracts aStream<List<int>>from a DioResponseBody(for real HTTP calls) or falls back to wrappingbodyBytes/bodyStringinto a single-chunk stream (for test clients and mocks).
Improvements #
- Visitor and writer updated to propagate
isStreamingthrough the full code generation pipeline. - Validator now rejects
@Streamingmethods that also declare@Multipartor@FormUrlEncoded. - API docs table in generated files now shows
[streaming]flag next to streamed endpoints.
1.3.2 #
- Repository Migration: Updated all repository, homepage, and package documentation references to the new Git repository
https://github.com/corevantdev/rest_client_builder. - Unit Test Stability: Updated outdated unit test assertions to match the new clean abstract class and generated
UserApiImplpattern.
1.3.1 #
- Minor Refinements: Internal documentation updates and dependency package adjustments.
1.3.0 #
- Zero-Setup DX Top-Level Getters: Automatically generates clean top-level getters (
demoApi,productApi,paymentApi) so controllers can invoke APIs directly with zeroRestClientmanagement or dependency injection boilerplate. - Pure Abstract API Declarations: Completely eliminated factory constructor requirements on
@RestApi()classes. - In-Memory Response Caching (
@Cache): Added@Cache(durationMs: ...)annotation for class and method levels. Eliminates network roundtrips for cached responses viaRestResponseCache. - Multi-Service & Microservice Architecture: Flexible support for single shared socket connection pools, microservice custom base URLs, and dedicated isolated client pools (
@RestApi(configuration: ...)). - Generator Variable Shadowing Fix: Renamed internal request variable in generated code to prevent shadowing method parameter names (
request,body, etc.).
1.2.1 #
- Refactored Code Generation: The builder now generates standalone
.g.dartfiles, completely removing the need forpartfiles. - Zero-Boilerplate Models: Removed the requirement to manually define
fromJson/toJsonmappings inside your@RestModel()classes. - Smart Imports: API generation automatically detects dependencies and imports the necessary source and generated files.
- Static Analysis & Dependencies: Updated
analyzer,dio, and other constraints. Addressed all static analysis warnings and documentation issues to achieve a perfect pub.dev score.
1.2.0 #
Initial stable release.
Added #
@RestApiannotation-driven REST client code generation viabuild_runner.@RestModelJSON code generation (fromJson/toJson) with fullJsonKeysupport.RestResult<T>sealed success/failure type withwhen,fold,map,flatMap,mapAsync,flatMapAsync,getOrThrow, andgetOrElse.RestErrortransport-agnostic structured error with factory constructors:unknown,validation,timeout,cancelled,connection,http, andserialization.DioRestClientwith retry, timeouts, header merging, logging, and interceptor resolution.RestPart.fromBytes/RestPart.fromBase64for web-safe multipart uploads (nodart:io).BasicCancelTokenfor cooperative cancellation withisCancelled/whenCancelled.RestProgressCallbackfor upload and download progress.@UseInterceptor/@ExcludeInterceptorper class or method.@Retry,@ConnectTimeout,@ReceiveTimeout,@SendTimeout,@EnableLogoverrides at the global, API, and endpoint levels.- Compile-time validation: duplicate routes, GET/HEAD + body, missing
@Path, invalid multipart combinations, and invalid return types. RestApiGlobalConfigurationcontract withcreateRestClient()factory (shared singleton) andcreateFreshRestClient()(isolated, for tests).RestApiClientRegistryfor shared Dio connection-pool reuse.CallbackRestClientfor easy unit testing without a network layer.DefaultInterceptorPipelinewith forward-request / reverse-response / reverse-error order.LoggingRestInterceptorwith sensitive-header redaction (Authorization,Cookie, etc.).- Generated
ApiDocs.endpointslist and dartdoc tables in every*.rest.g.dartfile. build.yamlbuilder registration — no consumerbuild.yamlrequired.- Full CRUD + multipart example under
example/. - 7 test suites covering core, runtime, validators, generator, and REST parts.