jaguar_retrofit

An HTTP client API generator inspired by Retrofit for Dart.

Install

dependencies:
  jaguar_retrofit:

dev_dependencies:
  jaguar_retrofit_gen:
  build_runner:

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

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: 'five@five.com'));

Libraries

jaguar.retrofit
Support for doing something awesome. [...]
jaguar.retrofit.client
retrofit.annotations
retrofit.annotations.params
retrofit.annotations.requests
utils