tryGet
inline suspend fun <R> ApiFetcher.tryGet(apiPath: String, headers: Map<String, Any>? = FetchDefaults.Headers, redirect: RequestRedirect? = FetchDefaults.Redirect, abortController: AbortController? = null, responseDeserializer: DeserializationStrategy<R> = serializer()): R?(source)
Deprecated
With these serialization-aware network methods, we are moving response deserialization handling to a separate `bodyAs` call. This lets us accomplish the same amount of functionality with fewer methods.
Replace with
import com.varabyte.kobweb.browser.tryGet
import com.varabyte.kobweb.browser.http.FetchDefaults
import com.varabyte.kobweb.browser.http.bodyAs
import kotlinx.serialization.serializer
Content copied to clipboard
tryGet(apiPath, headers, redirect, abortController) { bodyAs(responseDeserializer) }Content copied to clipboard
Like get, but returns null if the request fails or the response can't be deserialized.
Additionally, if ApiFetcher.logOnError is set to true, any failure will be logged to the console. By default, this will be true for debug builds and false for release builds.
Note: you should NOT prepend your path with "api/", as that will be added automatically.