retrofit dependencies in android studio kotlin
// Retrofit
    implementation 'com.squareup.retrofit2:retrofit:2.6.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.6.0'
    implementation "com.squareup.okhttp3:logging-interceptor:4.5.0"
kotlin and retrofit
- intoduction
        1. post is used to send data to server

- exapmle
   "simple post"
            @POST("posts")
            Call<Post> createPost(@Body Post post);

   "post with from url encoded "
            @FormUrlEncoded
            @POST("posts")
            Call<Post> createPost( @Field("userId") int userid ,
                                    @Field("title") String title,
                                    @Field("body") String body );

    "using map"
            @FormUrlEncoded
            @POST("posts")
            Call<Post> createPost(@FieldMap Map<String,String> postMap);







- INTERFACE
        public interface MyWebService {

            String BASE_URL = "https://jsonplaceholder.typicode.com/";
            String FEED = "posts";
            Retrofit retrofit = new Retrofit.Builder()
                    .baseUrl(BASE_URL)
                    .addConverterFactory(GsonConverterFactory.create())
                    .build();
        
            @GET(FEED)
            Call<List<Post>> getPosts();
        
        
        }



        
- MODEL CLASS
       public class Post {

            private int userId;
            private int id;
            private String title;
            private String body;
        
            public int getUserId() {
                return userId;
            }
        
            public void setUserId(int userId) {
                this.userId = userId;
            }
        
            public int getId() {
                return id;
            }
        
            public void setId(int id) {
                this.id = id;
            }
        
            public String getTitle() {
                return title;
            }
        
            public void setTitle(String title) {
                this.title = title;
            }
        
            public String getBody() {
                return body;
            }
        
            public void setBody(String body) {
                this.body = body;
            }
        
       }
        
        
        


- IN ACTIVITY WHERE TO SEND POST REQUEST
        Post post = new Post(1,"Post Title","this is post body");

        Map<String,String> postmap = new HashMap<>();
        postmap.put("userId","33");
        postmap.put("title","My post title");
        postmap.put("body","this is my post body in the map");
    
        Call<Post> postCall = myWebService.createPost(postmap);
        postCall.enqueue(new Callback<Post>() {
            @Override
            public void onResponse(Call<Post> call, Response<Post> response) {
                if (response.isSuccessful()){
                    textView.setText(String.valueOf(response.code()));
                    show(response.body());
                }
            }
    
            @Override
            public void onFailure(Call<Post> call, Throwable t) {
    
            }
        });

Kotlin相关代码片段

kotlin compiler

preety print a data class in kotlin

kotlin time taken

check internet reachable android kotlin

check network status android kotlin

check internet available on android kotlin

how to read a exel file in kotlin

square root in kotlin

convert list to string kotlin

splash screen in react native kotlin

view elevation android kotlin

abstraction in kotlin

singleton object in kotlin

round up in kotlin

keyboard options jetpack compose kotlin

Unresolved reference: Transformations

Fibonacci using an infinite sequence

options menu without an action bar android kotlin

kotlin when statement

Kotlin okhttp

compose, kotlin

import a external jar gradle kotlin

use viewbinding android

check if string is url android kotlin

inherit from button kotlin

inherit from view kotlin

give me above code in kotlin

check jks password

customSpinnerAdapter

Jetpack Compose make image fullsize

kotlin spring boot run code after component init

update kotlin gradle plugin

dictionary in kotlin

compare two numeric string values

kotlin create function

send method as parameter kotlin

pass class as parameter kotlin

set text to edittext android kotlin

minus kotlin

kotlin pair triple quadruple

how to validate email kotlin

Jetpack Compose custom switch

get string always defaulting

Jetpack Compose one sided stroke

android studio int to long

Android Kotlin Compose bottom bar

was ist bei der if anweisung dreimal === in kotlin

mapstruct to dto all fields null

set margins kotlin

kotlin serialization ignore field

kotlin interview questions android

kotlin list to string with separator

kotlin kapt plugin android

kotlin operators

kotlin variables

kotlin data types

kotlin comments

kotlin output

kotlin hello world 1.3

kotlin kotlin ide

can by lazy used with var in kotlin

open link in browser kotlin

how to kotlin get last string

how to write event calendar android kotlin

how to get .push string firebase kotlin

how to play background music in kotlin

room db android default value

Retrofit With MVI Architecture using Kotlin

viewbinding

bootstrap5 columns

check if variable is initialized kotlin

kotlin find max value in list of objects

kotlin time hours

how to create kotlin project in android studio

recyclerview kotlin grid layout

android studio change activity kotlin

create viewmodel instance android kotlin

context in kotlin

android kotlin local currency code and symbol

it implicit parameter kotlin