jvmMain.it.unibo.alchemist.boundary.webui.server.utility.Response.kt Maven / Gradle / Ivy
/*
* Copyright (C) 2010-2022, Danilo Pianini and contributors
* listed, for each module, in the respective subproject's build.gradle.kts file.
*
* This file is part of Alchemist, and is distributed under the terms of the
* GNU General Public License, with a linking exception,
* as described in the file LICENSE in the Alchemist distribution's top directory.
*/
package it.unibo.alchemist.boundary.webui.server.utility
import io.ktor.http.HttpStatusCode
import io.ktor.http.HttpStatusCode.Companion.OK
import io.ktor.server.application.ApplicationCall
import io.ktor.server.application.call
import io.ktor.server.response.respond
import io.ktor.util.pipeline.PipelineContext
/**
* Class representing an HTTP response.
* @param code the [HttpStatusCode].
* @param content the content of the message.
*/
data class Response(
val code: HttpStatusCode = OK,
val content: C,
) {
/**
* Utility functions.
*/
companion object {
/**
* Utility function to dry-run the response process.
*/
suspend inline fun PipelineContext.respond(response: Response) {
call.respond(response.code, response.content)
}
}
}