0

I'm trying to use post method in retrofit but confused how to implement it

How can I implement a retrofit using the post method?

{
    "companyId": "id8921",
    "employee": [
        {
            "id": "em128",
            "age": 38
        },
        {
            "id": "emp292",
            "age": 44
        },
        {
            "id": "emp321",
            "age": 33
        }
    ]
}

2 Answers 2

2

This how to post array object as form-url_encoded just use this in retrofit

@POST("api_url")
@FormUrlEncoded
Call<MasterResponse<JobCardSaveResponse>> jobCardSave(@FieldMap Map<String, Object> _jobCardRequest,
                                                      @Field("qty[]") List<String> qty,
                                                      @Field("service_id[]") List<String> service_id);
Sign up to request clarification or add additional context in comments.

Comments

2

use RequestBody data class :

data class RequestBody(
    val companyId: String,
    val employee: List<Employee>
)

data class Employee(
    val age: Int,
    val id: String
)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.