'Why it gets HTTP 404 error with @GET retrofit?

Api

interface Api {
    @GET("device/{id}")
    suspend fun getDetails(@Path("id") id: String): DetailsResponse
}

IMO it's good that's my documentation.

curl -X GET https://myApiDocumentation/device -d "id=[MY_ID]" -H "Authentication: [API_KEY]" --cookie "auth_key=[AUTH_KEY]" -G

Error http 404

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.project, PID: 21694
    retrofit2.HttpException: HTTP 404 
        at retrofit2.KotlinExtensions$await$2$2.onResponse(KotlinExtensions.kt:53)
        at retrofit2.OkHttpCall$1.onResponse(OkHttpCall.java:161)
        at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:519)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:923)

UseCase

class GetDetailsUseCase @Inject constructor(private val api: Api) : BaseApiRequestUseCase<GetDetailsUseCase.Params, DetailsResponse>() {
    override fun create(params: GetDetailsUseCase.Params) = flowSingle {
        api.getDetails(params.id)
    }

    data class Params(val id: String)

}

ViewModel

@HiltViewModel
class DetailsViewModel @Inject constructor(

    private val getDetailsUseCase: GetDetailsUseCase
) : BaseViewModel() {
    var details: Flow<DetailsResponse> =
        getDetailsUseCase.build(GetDetailsUseCase.Params(""))


    fun getDetails(id: String) {
        val params = GetDetailsUseCase.Params(id)
        details = getDetailsUseCase.build(params)
        details.onEach {
            val id = it.id
            val model = it.model
            Log.d("details", "WHAT IS IN THE PACKAGE +  $id $model")
        }
            .launchIn(viewModelScope)
    }
}

DetailsResponse

data class DetailsResponse(
    @SerializedName("id")
    val id: String,

   @SerializedName("model")
   val model: String,

)

fragment

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

// cameraId is value from previous fragment and it gives correct value
        getDetails(cameraId)
    }


    fun getDetails(id: String) {
        vm.getDetails(id)
        Log.d("details", "Fragment Det ${vm.getDetails(id)}")
    }

It crashes directly on it

details.onEach {
            val id = it.id
            val model = it.model
            Log.d("details", "WHAT IS IN THE PACKAGE +  $id $model")
        }
            .launchIn(viewModelScope)

What is your proposition to change the code, why it could go with error? It is almost code above, but I hope I give you full information about my situation.

I tried to make it with MutableShareFlow, but I am not sure about how to make it.

EDIT:

2022-02-20 11:53:56.890 30031-30120/com.google.android.calendar I/SyncerLog: [1] Response: {applied_change_ids=[], done_change_ids=[], server_change_count=9, change_set_details={mark_to_be_deleted=[2(none), 1(none), 3(<some_calendar>), 3(<some_calendar>), 3(<some_calendar>), 3(<some_calendar>)], delete_all_marked=[2(none), 1(none), 3(<some_calendar>), 3(<some_calendar>), 3(<some_calendar>), 3(<some_calendar>)], run_cleanup=[4(<some_calendar>), 4(<some_calendar>), 4(<some_calendar>)], acl=3, calendarListEntry=4, calendarSyncInfo=0, event=0, habit=0, setting=28, other=[]}, updated_sync_state={synced_user_settings=true, synced_habits=true, synced_calendar_list=true}, bad_sync_state=false, debug_info=Ch41RDg3MEVFQ0ZCQjkxLkFDMjUzOTUuNzUwRkZCODg=, call_sync=false, 
2022-02-20 12:50:23.651 31428-31428/com.example.api W/System.err:     at com.example.api.domain.CameraDetailsUseCase$create$1.invokeSuspend(GetDetailsUseCase.kt:12)

EDIT: FIXED I should use Query instead of Path


interface Api {
    @GET("device")
    suspend fun getDetails(@Query("id") id: String): DetailsResponse
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source