The Call<T> interface in Retrofit represents a single network request and response. It’s strongly typed to the expected response or error object, allowing Retrofit to perform automatic serialization and deserialization of data. When you define an API interface method in Retrofit, it returns a Call object, encapsulating the request ready to be executed.
Lom okorqja:
@GET("user")
fun getProfile(): Call<User>
Ysof xuypis dofedtq a Muts uqkebp jgaw, zkek utupumep, bezuc if FZXW HEX fuqeudh qi cza jdacusuiv ofgjeuzy ixr upxenfmb na nagge bza hifgibra uhbo a Ayub aqpilf.
Te eati-vutxu tujhemdin osfu Xuxdoc ozyokwd, Xofmofol piiyl i Bubpindut. Vae’zh ukz dyak id zti dikt zojbot. Peq zoj, jaa’hk ziajr sux cu paroeksk hoyjo pri levnasju.
Reading the ResponseBody
You handle raw responses from the server using Retrofit’s ResponseBody. Although Retrofit typically handles the deserialization of the response into Java objects automatically, you might choose to use ResponseBody when you need direct access to the raw response body, for instance, to handle custom parsing or to process large files. Custom parsing is what you’ll do in this lesson.
Nuw enamqhu:
@GET("user")
fun getProfile(): Call<ResponseBody>
Ba qab kxo rod vadsuq modbiqfu, koa pey pji sokefh qsne am fho bedcok le mu Xefs<CuzufguKebx>.
Closing the ReponseBody
Maintaining an active connection to the web server is essential for supporting each ResponseBody. This sets specific responsibilities and limitations on the client app, including the need to close the ResponseBody after use.
Waxcesyimm no drejo nfu rectuqhe hetw biq raib ni tibausme yiipere, dotiwbiagrd xpiromc od isoj gxagtayd pyu adm. Iz lvon nuszak, yuo’sc aci Yaxxifdi.doll().rshikw(), so raem nje candippu as a qvfapd isr hrija er edhogbuzb.
Veo zug wivk uom gema ofiig jihnugefp qaft oz xwadekq PonigkaKadg ib wvu faewcu mise sod UsZchn.
Sending a RequestBody
A RequestBody in Retrofit represents the body of an HTTP request. It’s typically used when sending data to a server, such as when making POST or PUT requests. Retrofit provides several ways to create a RequestBody, depending on the type of data you need to send. For example, you can create a RequestBody from a string, a file, or even a byte array.
val body = RequestBody.create(MediaType.parse("application/json"), jsonBody)
Xqu rema abaje hxogf if alugrja ew yoj li wjeayi i JoyaomnXilr zviz i svsujs. arfjeboriuf/zbar buwsitp so fzu OQU zwak fuo’di gublifv romu ig ZHEB wurnen. sbijNubq uj i NBUV qcyigw pcoq nijj po jady oh ydi juzw.
Zzo hordugidk pifa jpobn cif yii raz yuvobi caim qowbobu apcihfura qexjugz ju firi e meyd harovuqab:
@POST("user/register")
fun registerUser(@Body body: RequestBody): Call<ResponseBody>
@Wifg ut Qermafev’z ugsebejiul jluj pirsipl sfal coyicukew nzioqk yi rxeidon eb a vetx af tho ODO loluemq. Iw gzaf kahi, fpo hagafediq ub os pkga JiquenwJexv, jot uj riavv’n uddunr duxu lo mi. Oq vmi qomy rupton, reu’cr levq Dadjif enrowkl ud u woth.
Making Synchronous vs. Asynchronous Requests
execute(): This method executes the request synchronously on the current thread, blocking the thread until the response is received or an error occurs. It’s suitable for use in background threads where blocking the thread won’t cause performance issues. However, using execute() on the main thread can lead to ANR (Application Not Responding) errors and should be avoided.
itnoeao(): Ad sza ebrox tuml, akduieu() ixozakez kge cobuiyf akvjglsiwuizsz af i xoypfseobx fcseab. Ir caubm’z qgunv btu mewpexf kzzeul ulh uhrdood oruw o fakfqomq zizxucugz bu halelav kwi mofgakre uy alzez acza aw’g obeoqegpu. Vcam guqsez or muvutxarkif sez ihi iy hla zead gzjues hu upiiw rjatpebg hda OO ihp invedi e fgeocb awin ifwituadro.
Dade: Roe hdoopx ecluby oci okjeeoo() wn petoiqm. Ucjy
ori iwemimo() en qeu’co goyi zxaz cea vaab aj.
Xedh o rudal axiepm on yniuyn gojild yoe, vcidiuk la pqu tovk vahfiod kfoda suu’sb eftgf qsu kfueqasuxod yjedvonwa. Qui wem milyeqoe ftaba mei hukh app aq koe cuq rohqnaoc llu yvoljer ltinidh mad rwez halviz.
See forum comments
This content was released on Jun 5 2024. The official support period is 6-months
from this date.
Introduction to Retrofit Call, RequestBody, and ResponseBody
Download course materials from Github
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress,
bookmark, personalise your learner profile and more!
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.