http_api_generator 1.1.2 copy "http_api_generator: ^1.1.2" to clipboard
http_api_generator: ^1.1.2 copied to clipboard

A package that help you to generate Http Restful Api by annotation.

Features #

Generate Http api info by annotation

Getting started #

Add dependency to your pubspec:

http_api_generator: latest_version

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);
}

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;
1
likes
110
pub points
44%
popularity

Publisher

unverified uploader

A package that help you to generate Http Restful Api by annotation.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

analyzer, build, built_collection, code_builder, dart_style, meta, source_gen

More

Packages that depend on http_api_generator