Skip to content

Instantly share code, notes, and snippets.

@mariuszs
Last active August 29, 2015 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mariuszs/7266141206429e7e6428 to your computer and use it in GitHub Desktop.
Save mariuszs/7266141206429e7e6428 to your computer and use it in GitHub Desktop.

Fluent Rest client

class WeatherClient {
    String findCity(long latitude, long longitude) {
        return serviceRestClient.forExternalService()
                .get()
                .onUrl("$cityFindingServiceUrl?lat=${latitude.toInteger()}&lon=${longitude.toInteger()}")
                .anObject()
                .ofType(String)
    }
}

Retrofit client

interface WeatherClient {
    @GET("cityFindingService/?lat={latitude}&lon={latitude}")
    String findCity(long latitude, long longitude);
}

The mess

The mess with Fluent Rest client direct usage - without WeatherClient

    // with fluent rest client we are allowed to use direct code instead of WeatherClient
    for(location : locations)
       City city = serviceRestClient.forExternalService()
          .get()
          .onUrl("$cityFindingServiceUrl?lat=${location.latitude}&lon=${location.longitude}")
          .anObject()
          .ofType(String)
    
       City capital = serviceRestClient.forExternalService()
          .get()
          .onUrl("$cityFindingServiceUrl?lat=${latitude}&lon=${longitude}")
          .anObject()
          .ofType(String)

instead of

    for(location : locations)
       City city = weatherClient.findCity(location.latitude, location.longitude)
    
       City capital = weatherClient.findCity(latitude, longitude)

You cant make a mess with retrofit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment