Tools every Android developer must know by heart Series
#1 Retrofit
- Retrofit — https://square.github.io/retrofit/
Developed by square Retrofit is a type-safe HTTP client for Android and Java.
It allows developers to develop API requests in a simplified way.
Through annotations a developer can describe there HTTP requests:
- URL parameter replacement and query parameter support
- Object conversion to request body (e.g., JSON, protocol buffers)
- Multipart request body and file upload
Components
- Request method
Every method must have an HTTP annotation that provides the request method and relative URL. There are eight built-in annotations: HTTP
, GET
, POST
, PUT
, PATCH
, DELETE
, OPTIONS
and HEAD
.
@GET("users/list")
@POST("users/updateProfile")
2. URL manipulation
A request URL can be updated dynamically using replacement blocks and parameters on the method. A replacement block is an alphanumeric string surrounded by {
and }
. A corresponding parameter must be annotated with @Path
using the same string.
@GET("group/{id}/profile")
Call<List<User>> groupList(@Path("id") int groupId)…