Skip to content

Instantly share code, notes, and snippets.

@shikajiro
Last active December 30, 2015 06:28
Show Gist options
  • Save shikajiro/7789111 to your computer and use it in GitHub Desktop.
Save shikajiro/7789111 to your computer and use it in GitHub Desktop.
AnndroidAnnotationsによる一般的な@rest
@EActivity
public class HogeActivity{
@Rest WebApi webApi;
public void hoge(){
try{
UserJson json = webApi.getUser(1234);
return json;
}catch(RestClientException e){
//HTTPエラー処理
//RestClientException は非チェック例外
}
}
}
@Rest(rootUrl = "http://hogehoge.com/hogehoge/", converters = { MappingJacksonHttpMessageConverter.class }, interceptors = {RestInterceptor.class})
public interface WebApi {
@Get("user/{id}")
UserJson getUser(long id);
@Post("user")
void postUser(UserJson user);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment