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

commonMain.request.RequestHandler.kt Maven / Gradle / Ivy

package dev.kord.rest.request

import dev.kord.common.KordConstants
import io.ktor.http.HttpHeaders.Authorization
import io.ktor.http.HttpHeaders.UserAgent

/**
 * Handles Discord API requests.
 */
public interface RequestHandler {

    /**
     * The Discord bot authorization token used on requests.
     */
    public val token: String

    /**
     * Executes the [request], abiding by the active rate limits and returning the response [R].
     *
     * @throws RestRequestException when a non-rate limit error response is returned.
     */
    public suspend fun  handle(request: Request): R

    public suspend fun  intercept(builder: RequestBuilder) {
        builder.apply {
            unencodedHeader(UserAgent, KordConstants.USER_AGENT)
            if (route.requiresAuthorizationHeader) {
                unencodedHeader(Authorization, "Bot $token")
            }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy