Source点
Http路由
其他Demo
let client = Retrofit.getBuilder()
.setConfig<RetrofitConfig>( { /** config, you can use retrofit config or axios config */ } )
.addInterceptor( /** your interceptor */ )
.setErrorHandler( /** define your error handler */ )
.build();
// This is the part of define any interface what you need.
@HTTP( "/testing" )
@Headers( [ "Cache-Control: no-store" ] )
class TestingClient {
@GET( "/demo1/:callByWho/:when" )
public demo1( @Path( "callByWho" ) name: string, @Path( "when" ) time: number ): RetrofitPromise<string> & void {
}
@POST( "/demo2/:file" )
public demo2( @Path( "file" ) file: string, @Header( "cookie" ) val: string, @Config localConfig: AxiosConfig ): RetrofitPromise<string> & void {
}
}
// The final step, create your client.
export let testingClient = client.create( TestingClient );
// When you are calling this method, it is a http call actually.
testingClient.demo1( "itfinally", Date.now() ).then( response => {
// any code
} ).catch( reason => {
// any code
} );
// And you can also get axios instance.
let axios: AxiosInstance = client.getEngine();
参考书目