All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.service.RestService.kt Maven / Gradle / Ivy

The newest version!
package dev.kord.rest.service

import dev.kord.rest.request.RequestBuilder
import dev.kord.rest.request.RequestHandler
import dev.kord.rest.route.Route
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract

public abstract class RestService(@PublishedApi internal val requestHandler: RequestHandler) {

    @PublishedApi
    internal suspend inline fun  call(route: Route, builder: RequestBuilder.() -> Unit = {}): T {
        contract {
            callsInPlace(builder, InvocationKind.EXACTLY_ONCE)
        }
        val interceptedBuilder = RequestBuilder(route).apply(builder)
        requestHandler.intercept(interceptedBuilder)

        val request = interceptedBuilder.build()
        return requestHandler.handle(request)
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy