commonMain.request.RequestHandler.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kord-rest Show documentation
Show all versions of kord-rest Show documentation
Idiomatic Kotlin Wrapper for The Discord API
The newest version!
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")
}
}
}
}