retrofit.dart
retrofit.dart copied to clipboard
Add @Url annotation to pass full url for a particular function
There is a use-case where we have infinite list of data and API supports pagination. The response sends the url of the next page and we need to call that url to get the data for that page. Currently there is no @Url parameter (as it is in the native Android Retrofit library) so it is not possible to pass separate url for a particular function. There is one work-around to split the url into base url and paths and use @Path in the function, but I think it's not a good solution. Please look into this.
Also for this, we need to have optional path parameter in the @GET annotation to support this use-case
Did you try something like the below
@GET("https://httpbin.org/status/204")
Future<HttpResponse<void>> reponseWith204();
@trevorwang the url will be dynamic and will be sent as a parameter to the function. In your example it is static value. Like this one - https://square.github.io/retrofit/2.x/retrofit/retrofit2/http/Url.html
Add @Url annotation to pass full url for a particular function
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
wontfix flag seems to be automatic. It would be a nice feature especially useful when trying to download a photo with a dynamic url.
Please try to use dio directly in this scenario
response = await dio.download('https://www.google.com/', './xx.html');
Hey @intkhabahmed,
I believe that you can have your method to take an options by having @DioOptions annotation like so:
@RestApi()
abstract class Api {
factory Api(Dio dio, {String baseUrl}) = _Api;
@GET('path')
Future<void> getTest(
@DioOptions() RequestOptions options,
);
}
By doing this, you'll have an options that allows you to pass different urls like so:
final dio = Dio();
Api(dio).getTest(
RequestOptions(
path: 'your/different/path'
// other options...
),
);
Hope this helps you out, Please consider closing the issue if you found this solution is what you exactly need!
@devmuaz This method is indeed feasible, but it requires modifying the automatically generated g.dart file, otherwise the passed path and parameters will be invalid . newOptions.copyWith() need modify