본문 바로가기

안드로이드

retroift @query , @path 주소(url) example

반응형



예를들어 

http://leesmemo.tistory.com/admin/entry/post/?id=2 식의 url이 있다고 치면


url = "http://leesmemo.tistory.com/"


(kotlin으로 작성)

@GET("{admin}/{entry}/{post}")

Call<보내주는 모델객체의 변수들을 포함한 클래스(전부 혹은 일부와 같은 변수를 가진 클래스(변수들의의 네이밍 또한 같아야한다.))> 

getInfo(@Path("admin") String andmin, @Path("entry") String entryee, @Path("post") String post, @Query("id") String id);


사실 admin이나 entry, post는 바뀔 필요가 없지만.. 예제 이므로 위와 같이 path를 사용해 주었다.

path의 admin에 "a"를 주고 entry에 "b", post에 "c", "id"에 6을 준다면

http://leesmemo.tistory.com/a/b/c/?id=6

이런식의 주소로 이동한다.



@POST방식도 GET방식과 동일하게 Path, Query값을 넣어주면된다.


반응형