Last updated:
0 purchases
jaguar retrofit
jaguar_retrofit #
An HTTP client API generator inspired by Retrofit for Dart.
Install #
dependencies:
jaguar_retrofit:
dev_dependencies:
jaguar_retrofit_gen:
build_runner:
copied to clipboard
Defining and ApiClient
/// Example showing how to define an [ApiClient]
/// Example showing how to define an [ApiClient]
@GenApiClient(path: "user")
class UserApi extends ApiClient with _$UserApiClient {
final resty.Route base;
UserApi(this.base);
@GetReq(path: ":id")
Future<User> getUserById(@PathParam() String id);
@GetReq()
Future<List<User>> all();
@PostReq()
Future<User> createUser(@AsJson() User user);
@PutReq(path: ":id")
Future<User> updateUser(String id, @AsJson() User user);
@DeleteReq(path: ":id")
Future<void> deleteUser(String id);
@PostReq(path: "/login")
Future<void> login(@AsForm() Login login);
@PatchReq(path: "/avatar")
Future<void> avatar(@AsBody() List<int> data);
@PostReq()
Future<User> serialize(@Serialized(MimeTypes.json) User data);
}
copied to clipboard
Generate
pub run build_runner build
Use it
final repo = JsonRepo()..add(UserSerializer());
final api = UserApi(base: route("http://localhost:10000"))..jsonConverter = repo;;
User user = await api
.createUser(User(id: '5', name: 'five', email: '[email protected]'));
copied to clipboard
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.