trevorwang / retrofit.dart

retrofit.dart is an dio client generator using source_gen and inspired by Chopper and Retrofit.
https://mings.in/retrofit.dart/
MIT License
1.08k stars 246 forks source link

Add nested url's support #651

Open DenisBogatirov opened 8 months ago

DenisBogatirov commented 8 months ago

Is your feature request related to a problem? Please describe. Oftenly you will have different clients for different API entities like users, auth, settigns etc. As well as different envs. And it's a giant chore to have only baseUrl and adding /users, /auth, /settings to each single request.

Describe the solution you'd like Ideal solution would be if baseUrl in constructor is defined or Dio.baseUrl is not null then add RestApi.baseUrl at the end of previous url.

Describe alternatives you've considered To avoid breaking changes and confusion add something like RestApi.nestedUrl and if it's present then add it to the basae url.

Additional context Ultimate goal is something like this

@RestApi(nestedUrl: '/users')
abstract class RestClient {
  factory RestClient(Dio dio, {
    String baseUrl // https://api.com Provided from ENV
}) = _RestClient;

  @GET('/{id}') // will point towards https://api.com/users/{id}
  Future<User> getUser(@Path('id') String id);
}