Http

object Http

a singleton class that holds utils common to the Http.

Properties

Link copied to clipboard
const val CONNECTION_TIME_OUT_MILLIS: Long = 30000

API's connection time out in milli seconds

Link copied to clipboard
val ktorConfigJson: Json

sets up Ktor Json Configuration.

Link copied to clipboard
const val REQUEST_TIME_OUT_MILLIS: Long = 30000

API's request time out in milli seconds

Functions

Link copied to clipboard
suspend fun ResponseException.asClientException(message: String = "", cause: Throwable? = null): ClientException

similar to the HttpResponse.asClientException only that it covers the ResponseException thrown by Ktor.

suspend fun HttpResponse.asClientException(message: String = "", cause: Throwable? = null): ClientException

Constructs a ClientException based on the HttpResponse

Link copied to clipboard
fun getUserAgent(platform: Platform, clientSDKName: String, clientSDKVersion: String?, appName: String?, appVersion: String?): String

To build a user agent that provide information where this sdk is being used, on client level pass app-version. here we can read the client version. on client sdk level pass client-name and append. and client version on core level read platform level and append. if the value userAgent is null then we pass platform as default. sample output android core-client/0.0.19/ app-version/11.40.0

Link copied to clipboard
fun HttpResponse.hasStatus(status: HttpStatusCode): Boolean

Returns a Boolean indicating whether the HttpResponse has the specified status code. Reusable, as we can reuse the hasStatus function to check for multiple status codes. rather than creating a single method for each status check e.g isOK,isAccepted,is.....

Link copied to clipboard
fun protocol(protocol: String?): URLProtocol
Link copied to clipboard
fun HttpResponse.successful(): Boolean

Returns a Boolean indicating whether the HttpResponse is successful.