Retrofit 2.0.0 正式發布,Android 的 REST 客戶端

2021-01-10 開源中國

Retrofit 2.0.0 正式發布了,retrofit 是一個類型安全的 REST 客戶端,用於 Android 平臺。。

該版本的重點是提升擴展性,因此包含大量 API 的改動,與上一個版本不兼容。詳細的變化請看這裡。

與 Beta4 版本比較的改進包括:

New: RxJavaCallAdapterFactory now supports service methods which return Completable whichignores and discards response bodies, if any.

New: RxJavaCallAdapterFactory supports supplying a default Scheduler which will be usedfor subscribeOn on returned Observable, Single, and Completable instances.

New: MoshiConverterFactory supports creating an instance which uses lenient parsing.

New: @Part can omit the part name and use OkHttp's MultipartBody.Part type for supplyingparts. This lets you customize the headers, name, and filename and provide the part body in asingle argument.

The BaseUrl interface and support for changeable base URLs was removed. This functionalitycan be done using an OkHttp interceptor and a sample showcasing it was added.

Response.isSuccess() was renamed to Response.isSuccessful() for parity with the name ofOkHttp's version of that method.

Fix: Throw a more appropriate exception with a message when a resolved url (base URL + relativeURL) is malformed.

Fix: GsonConverterFactory now honors settings on the Gson instance (like leniency).

Fix: ScalarsConverterFactory now supports primitive scalar types in addition to boxed forresponse body parsing.

Fix: Retrofit.callbackExecutor() may now return an executor even when one was not explicitlyprovided. This allows custom CallAdapter.Factory implementations to use it when triggeringcallbacks to ensure they happen on the appropriate thread for the platform (e.g., Android).

下載地址:

https://github.com/square/retrofit/releases/tag/parent-2.0.0

相關焦點