Version 2.2.0 (2017-02-21)
- RxJava 2.x is now supported with a first-party ‘adapter-rxjava2’ artifact.
- New:
@QueryName
annotation allows creating a query parameter with no ‘=’ separator or value. - New: Support for messages generated by Protobuf 3.0 or newer when using the converter for Google’s protobuf.
- New: RxJava 1.x call adapter now correctly handles broken subscribers whose methods throw exceptions.
- New: Add
toString()
implementations forResponse
andResult
. - New: The Moshi converter factory now offers methods for enabling null serialization and lenient parsing.
- New: Add
createAsync()
to RxJava 1.x call adapter factory which executes requests usingCall.enqueue()
using the underlying HTTP client’s asynchronous support. - New:
NetworkBehavior
now allows setting an error percentage and returns HTTP errors when triggered. HttpException
has been moved into the main artifact and should be used instead of the versions embedded in each adapter (which have been deprecated).- Promote the response body generic type on
CallAdapter
from theadapt
method to the enclosing class. This is a source-incompatible but binary-compatible change which is only relevant if you are implementing your ownCallAdapter
s. - Remove explicit handling of the now-defunct RoboVM platform.
- Fix: Close response on HTTP 204 and 205 to avoid resource leak.
- Fix: Reflect the canceled state of the HTTP client’s
Call
in Retrofit’sCall
. - Fix: Use supplied string converters for the
String
type on non-body parameters. This allows user converters to handle cases such as when annotating string parameters instead of them always using the raw string. - Fix: Skip a UTF-8 BOM (if present) when using the converter for Moshi.
Version 2.0.2 (2016-04-14)
- New:
ProtoConverterFactory.createWithRegistry()
method accepts an extension registry to be used when deserializing protos. - Fix: Pass the correct
Call
instance toCallback
‘sonResponse
andonFailure
methods such that callingclone()
retains the correct threading behavior. - Fix: Reduce the per-request allocation overhead for the RxJava call adapter.
Version 2.0.0 (2016-03-11)
Retrofit 2 is a major release focused on extensibility. The API changes are numerous but solve shortcomings of the previous version and provide a path for future enhancement.
Because the release includes breaking API changes, we’re changing the project’s package name from retrofit
to retrofit2
. This should make it possible for large applications and libraries to migrate incrementally. The Maven group ID is now com.squareup.retrofit2
. For an explanation of this strategy, see Jake Wharton’s post, Java Interoperability Policy for Major Version Updates.
-
Service methods return
Call<T>
. This allows them to be executed synchronously or asynchronously using the same method definition. ACall
instance represents a single request/response pair so it can only be used once, but you canclone()
it for re-use. Invokingcancel()
will cancel in-flight requests or prevent the request from even being performed if it has not already. -
Multiple converters for multiple serialization formats. API calls returning different formats (like JSON, protocol buffers, and plain text) no longer need to be separated into separate service interfaces. Combine them together and add multiple converters. Converters are chosen based on the response type you declare. Gson is no longer included by default, so you will always need to add a converter for any serialization support. OkHttp’s
RequestBody
andResponseBody
types can always be used without adding one, however. -
Call adapters allow different execution mechanisms. While
Call
is the built-in mechanism, support for additional ones can be added similar to how different converters can be added. RxJava’sObservable
support has moved into a separate artifact as a result, and support for Java 8’sCompletableFuture
and Guava’sListenableFuture
are also provided as additional artifacts. -
Generic response type includes HTTP information and deserialized body. You no longer have to choose between the deserialized body and reading HTTP information. Every
Call
automatically receives both via theResponse<T>
type and the RxJava, Guava, and Java 8 call adapters also support it. -
@Url for hypermedia-like APIs. When your API returns links for pagination, additional resources, or updated content they can now be used with a service method whose first parameter is annotated with
@Url
.
Changes from beta 4:
- New:
RxJavaCallAdapterFactory
now supports service methods which returnCompletable
which ignores and discards response bodies, if any. - New:
RxJavaCallAdapterFactory
supports supplying a defaultScheduler
which will be used forsubscribeOn
on returnedObservable
.Single
, andCompletable
instances. - New:
MoshiConverterFactory
supports creating an instance which uses lenient parsing. - New:
@Part
can omit the part name and use OkHttp’sMultipartBody.Part
type for supplying parts. This lets you customize the headers, name, and filename and provide the part body in a single argument. - The
BaseUrl
interface and support for changeable base URLs was removed. This functionality can be done using an OkHttp interceptor and a sample showcasing it was added. Response.isSuccess()
was renamed toResponse.isSuccessful()
for parity with the name of OkHttp’s version of that method.- Fix: Throw a more appropriate exception with a message when a resolved url (base URL + relative URL) is malformed.
- Fix:
GsonConverterFactory
now honors settings on theGson
instance (like leniency). - Fix:
ScalarsConverterFactory
now supports primitive scalar types in addition to boxed for response body parsing. - Fix:
Retrofit.callbackExecutor()
may now return an executor even when one was not explicitly provided. This allows customCallAdapter.Factory
implementations to use it when triggering callbacks to ensure they happen on the appropriate thread for the platform (e.g., Android).
Version 2.0.0 – beta4(2016-02-04)
- New:
Call
instance is now passed to bothonResponse
andonFailure
methods ofCallback
. This aids in detecting whenonFailure
is called as a result ofCall.cancel()
by checkingCall.isCanceled()
. - New:
Call.request()
returns (optionally creating) theRequest
object for the call. Note: If this is called beforeCall.execute()
orCall.enqueue()
this will do relatively expensive work synchronously. Doing so in performance-critical sections (like on the Android main thread) should be avoided. - New: Support for the release version of OkHttp 3.0 and newer.
- New:
adapter-guava
module provides aCallAdapter.Factory
for Guava’sListenableFuture
. - New:
adapter-java8
module provides aCallAdapter.Factory
for Java 8’sCompleteableFuture
. - New:
ScalarsConverterFactory
(fromconverter-scalars
module) now supports parsing response bodies into eitherString
, the 8 primitive types, or the 8 boxed primitive types. - New: Automatic support for sending callbacks to the iOS main thread when running via RoboVM.
- New: Method annotations are now passed to the factory for request body converters. This allows converters to alter the structure of both request bodies and response bodies with a single method-level annotation.
- Each converter has been moved to its own package under
retrofit2.converter.<name>
. This prevents type collisions when many converters are simultaneously in use. - Fix: Exceptions thrown when unable to locate a
CallAdapter.Factory
for a method return type now correctly list theCallAdapter.Factory
instances checked. - Fix: Ensure default methods on service interfaces can be invoked.
- Fix: Correctly resolve the generic parameter types of collection interfaces when subclasses of those collections are used as method parameters.
- Fix: Do not encode
/
characters in@Path
replacements whenencoded = true
.
Version 2.0.0 – beta 2(2015-09-28)
- New: Using a response type of
Void
(e.g.,Call<Void>
) will ignore and discard the response body. This can be used when there will be no response body (such as in a 201 response) or whenever the body is not needed.@Head
requests are now forced to use this as their response type. - New:
validateEagerly()
method onRetrofit.Builder
will verify the correctness of all service methods on calls tocreate()
instead of lazily validating on first use. - New:
Converter
is now parameterized over both ‘from’ and ‘to’ types with a singleconvert
method.Converter.Factory
is now an abstract class and has factory methods for both request body and response body. - New:
Converter.Factory
andCallAdapter.Factory
now receive the method annotations when being created for a return/response type and the parameter annotations when being created for a parameter type. - New:
callAdapter()
method onRetrofit
allows querying aCallAdapter
for a given type. ThenextCallAdapter()
method allows delegating to anotherCallAdapter
from within aCallAdapter.Factory
. This is useful for composing call adapters to incrementally build up behavior. - New:
requestConverter()
andresponseConverter()
methods onRetrofit
allow querying aConverter
for a given type. - New:
onResponse
method inCallback
now receives theRetrofit
instance. Combined with theresponseConverter()
method onRetrofit
, this provides a way of deserializing an error body onResponse
. See theDeserializeErrorBody
sample for an example. - New: The
MoshiConverterFactory
Has been updated for its V1.0.0. - Fix: Using
ResponseBody
for the response type orRequestBody
for a parameter type is now correctly identified. Previously these types would erroneously be passed to the supplied converter. - Fix: The encoding of
@Path
values has been corrected to conform to OkHttp’sHttpUrl
. - Fix: Use form-data content disposition subtype for
@Multipart
. - Fix:
Observable
andSingle
-based execution of requests now behave synchronously (and thus requiressubscribeOn()
for running in the background). - Fix: Correct
GsonConverterFactory
to honor the configuration of theGson
instances (such as not serializing null values, the default).
Version 1.9.0 (2015-01-07)
- Update to OkHttp 2.x’s native API. If you are using OkHttp you must use version 2.0 or newer (the latest is 2.2 at time of writing) and you no longer need to use the
okhttp-urlconnection
shim. - New: Allow disabling Simple XML Framework’s strict parsing.
- New:
@Header
now accepts aList
or array for a type. - New:
@Field
and@FieldMap
now have options for enabling or disabling URL encoding of names and values. - Fix: Remove query parameters from thread name when running background requests for asynchronous use.
Version 1.7.1 (2014-10-23)
- Fix: Correctly log
null
request arguments forHEADERS_AND_ARGS
log level.
Version 1.6.1 (2014-07-02)
- Fix: Add any explicitly-specified ‘Content-Type’ header (via annotation or param) to the request even if there is no request body (e.g., DELETE).
- Fix: Include trailing CRLF in multi-part uploads to work around a bug in .NET MVC 4 parsing.
- Fix: Allow
null
mock exception bodies and use the success type from the declared service interface.
Version 1.5.1 (2014-05-08)
- New:
@PartMap
annotation accepts aMap
of key/value pairs for multi-part. - Fix:
MockRestAdpater
uses theErrorHandler
from its parentRestAdapter
. - Experimental RxJava support updated for V0.18 and is now Lazily initialized
Version 1.4.1 (2014-02-01)
- Fix:
@QueryMap
.@EncodedFieldMap
, and@FieldMap
now correctly detectMap
-based parameter types.
Version 1.3.0 (2013-11-25)
- New: Converter module for SimpleXML.
- New: Mock module which allows simulating real network behavior for local service interface implementations. See ‘mock-github-client’ example for a demo.
- New: RxJava
Observable
support! Declare a return type ofObservable<Foo>
on your service interfaces to automatically get an observable for that request. (Experimental API) - Fix: Use
ObjectMapper
‘s type factory when deserializing (Jackson converter). - Multipart POST requests now stream their individual part bodies.
- Log chunking to 4000 characters now only happens on the Android platform.
Version 1.2.1 (2013-08-30)
- New: Converter for Wire protocol buffers!
Version 1.2.0 (2013-08-23)
- New: Additional first-party converters for Jackson and Protocol Buffers! These are provided as separate modules that you can include and pass to
RestAdapter.Builder
‘ssetConverter
. - New:
@EncodedPath
and@EncodedQuery
annotations allow provided path and query params that are already URL-encoded. - New:
@PATCH
HTTP method annotation. - Fix: Properly support custom HTTP method annotations in
UrlConnectionClient
. - Fix: Apply
RequestInterceptor
during method invocation rather than at request execution time. - Change
setDebug
tosetLogLevel
onRestAdapter
andRestAdapter.Builder
and provide two levels of logging viaLogLevel
. - Query parameters can now be added in a request interceptor.
Version 1.1.0 (2013-06-20)
- Introduce
RequestInterceptor
to replaceRequestHeaders
. An interceptor provided to theRestAdapter.Builder
will be called for every request and allow setting both headers and additional path parameter replacements. - Add
ErrorHandler
for customizing the exceptions which are thrown when synchronous methods return non-200 error codes. - Properly parse responses which erroneously omit the “Content-Type” header.
Version 1.0.1 (2013-05-13)
- Fix: Correct bad regex behavior on Android.