![retrofit file upload example retrofit file upload example](https://www.agiratech.com/wp-content/uploads/2018/11/How-to-use-retrofit-on-android-with-Kotlin.jpg)
![retrofit file upload example retrofit file upload example](https://abhiandroid.com/programming/wp-content/uploads/2018/01/Retrofit-In-Android.png)
Each instance can only be used once, but calling clone() will create a new instance that can be used. Headers that need to be added to every request can be specified using an OkHttp interceptor.Ĭall instances can be executed either synchronously or asynchronously.
![retrofit file upload example retrofit file upload example](https://www.simplifiedcoding.net/wp-content/uploads/2017/10/retrofit-upload-file-tutorial.png)
Similar to query parameters, for complex header combinations, a Map can be Map headers) Otherwise, toString will be called on the value, and the result used. A corresponding parameter must be provided to the If the value is null, the header will be omitted. All headers with the same name will be included in the request.Ī request Header can be updated dynamically using the annotation. Note that headers do not overwrite each other. You can set static headers for a method using the annotation. Multipart parts use one of Retrofit's converters or they can implement RequestBody to handle their own serialization. RequestBody photo, RequestBody description) Multipart requests are used when is present on the method. Each key-value pair is annotated with containing the name and the object providing the value. Methods can also be declared to send form-encoded and multipart data.įorm-encoded data is sent when is present on the method. If no converter is added, only RequestBody can be used. The object will also be converted using a converter specified on the Retrofit instance. int groupId, Map options) Request BodyĪn object can be specified for use as an HTTP request body with the annotation. int groupId, String sort) įor complex query parameter combinations a Map can be used. A corresponding parameter must be annotated with using the same string. A replacement block is an alphanumeric string surrounded by. URL ManipulationĪ request URL can be updated dynamically using replacement blocks and parameters on the method. can also specify query parameters in the URL. The relative URL of the resource is specified in the annotation. There are eight built-in annotations: HTTP, GET, POST, PUT, PATCH, DELETE, OPTIONS and HEAD. Request MethodĮvery method must have an HTTP annotation that provides the request method and relative URL. Object conversion to request body (e.g., JSON, protocol buffers)Īnnotations on the interface methods and its parameters indicate how a request will be handled.URL parameter replacement and query parameter support.Use annotations to describe the HTTP request: Call> repos = service.listRepos("octocat") GitHubService service = retrofit.create(GitHubService.class) Įach Call from the created GitHubService can make a synchronous or asynchronous HTTP request to the remote webserver. Retrofit retrofit = new Retrofit.Builder() The Retrofit class generates an implementation of the GitHubService interface. public interface GitHubService String user) Retrofit turns your HTTP API into a Java interface.