Android

JAVA Retrofit2

Machine_웅 2019. 11. 14. 17:03
728x90
반응형

interface 생성

public interface user_data_inter {

    @FormUrlEncoded
    @POST("api/users")
    Call<String> check_nick (
            @Field("nick") String nick
    );


 // in Java
 /*
    @GET("api/unknown")
    Call<MultipleResource> doGetListResources();

    @POST("api/users")
    Call<User> createUser(@Body User user);

    @GET("api/users?")
    Call<UserList> doGetUserList(@Query("page") String page);

    @FormUrlEncoded
    @POST("api/users?")
    Call<UserList> doCreateUserWithField(@Field("name") String name, @Field("job") String job);
*/
}

 

메인 코드

        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl("주소")
                .addConverterFactory(GsonConverterFactory.create())
                .build();

        retro_userDataInterface = retrofit.create(user_data_inter.class); // 인터페이스

        retro_userDataInterface.check_nick(input_nick).enqueue(new Callback<String>() {
            @Override
            public void onResponse(Call<String> call, Response<String> response) {

            }

            @Override
            public void onFailure(Call<String> call, Throwable t) {

            }
        });
728x90
반응형