Last updated:
0 purchases
http api generator
Features #
Generate Http api info by annotation
Getting started #
Add dependency to your pubspec:
http_api_generator: latest_version
copied to clipboard
Usage #
part 'login.api.g.dart';
@RestApi()
abstract class LoginApi {
factory LoginApi() => _LoginApi();
@POST("app/login")
HttpApi<UserEntity> login(@Body() LoginRequest request);
@GET("app/{userId}")
HttpApi<UserEntity?> getUser(@Path() String userId);
}
copied to clipboard
Then run the build_runner by 'flutter packages pub run build_runner build'.
You can get the following information from the generated HttpApi:
/// @Method
String method;
/// Url of @Method and @Path
String url;
/// baseUrl in @HttpApi
String? baseUrl;
/// @Body
Object? body;
/// @Query
Map<String, dynamic>? queryParams;
/// @Field
Map<String, dynamic>? fields;
/// @FormUrlEncoded
bool formUrlEncoded;
/// Type of response, as T
Type responseType;
/// @FromJson
FromJsonTransform<RESPONSE>? fromJson;
/// @Options, contains headers, responseType, receiveTimeout, sendTimeout
final HttpOptions? options;
copied to clipboard
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.