Jaguar-dart/client

Base path for ApiClient

jaumard opened this issue · 8 comments

Would be nice to be able to do:

/// Example showing how to define an [ApiClient]
@GenApiClient("users")
class UserApi extends _$UserApiClient implements ApiClient {
  final resty.Route base;

  final SerializerRepo serializers;

  UserApi({this.base, this.serializers});

  @GetReq("/:id")
  Future<User> getUserById(String id);

  @PostReq("/")
  Future<User> createUser(@AsJson() User user);

  @PutReq("/:id")
  Future<User> updateUser(String id, @AsJson() User user);

  @DeleteReq("/:id")
  Future<void> deleteUser(String id);

  @GetReq("/")
  Future<List<User>> all({String name, String email});
}

Will fix it.

Kleak commented

Why not put it into
@GenApiClient("users", base: "https://other-website.com/")

@Kleak by putting the base here we can't easily add interceptors later right ? because we'll not have the "base" route param to pass to the constructor ?

Kleak commented

If interceptor a annotations based these will not be a problem to get the base url

But interceptors can be by route, if they become annotation they are now global because you can't know for witch route you want it :/ you loose in granularity

Kleak commented

Do you have different base for one GenApiClient ?

I think, we should keep base member of GenApiClient. In addition we can add path parameter to GenApiClient @GenApiClient(path: "users").

I think the origin part of the url is better left to base member. Then you can use same ApiClient for multiple origins.

Right now, one can add interceptors to base member. There is no way to add them declarative-ly using annotations. A future enhancement. Please, open an issue for this.

@Kleak @tejainece having a path into GenApiClient is exactly what I need, I'm trying to keep Api per domain so each api will have a path.