Enviar y recibir datos en JSON con Retrofit

Uso de Retrofit para realizar peticiones GET, POST, PUT y DELETE

Cómo consumir una API y procesar la respuesta usando Retrofit

Define the endpoints

How to get JSON using Retrofit

public interface RetrofitClient {
      //https://api.github.com/users/azemZejnil/repos is whole URL

     //"users/{user}/repos" is the part of URL will be added to base URL. 
    //List<GithubRepo> is return type    @Path("user")String user is the parameter we will pass           
    Call<List<GithubRepo>> reposForUser(@Path("user")String user);

How to Send JSON Data in a POST Request in Android

public interface CommentsService {
    Call<Comment> createComment(@Body Comment comment);

    Call<Comment> createComment(@Field("title") String title, @Field("comment") String comment, @Field("author") String author);

    Call<Comment> createComment(@FieldMap Map<String, String> fields);

Código en Github

Retrofit 2 CRUD Android Example

public interface UserService {

    Call<List<User>> getUsers();

    Call<User> addUser(@Body User user);

    Call<User> updateUser(@Path("id") int id, @Body User user);

    Call<User> deleteUser(@Path("id") int id);


Deja una respuesta