Last active
May 18, 2020 08:41
-
-
Save adamw/f7913469c503ea822e43e3c7c7759dd7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.UUID | |
import io.circe.generic.auto._ | |
import sttp.model.StatusCode | |
import sttp.tapir._ | |
import sttp.tapir.json.circe._ | |
object Endpoints { | |
case class AuthToken(token: String) | |
case class Error(msg: String, statusCode: StatusCode) extends Exception | |
case class User(id: UUID, name: String) | |
case class Pet(id: UUID, kind: String, name: String) | |
val error: EndpointOutput[Error] = stringBody.and(statusCode).mapTo(Error) | |
val baseEndpoint: Endpoint[AuthToken, Error, Unit, Nothing] = | |
endpoint | |
.in(auth.apiKey(cookie[String]("Token")).mapTo(AuthToken)) | |
.in("api" / "1.0") | |
.errorOut(error) | |
val getPet: Endpoint[(AuthToken, UUID), Error, Pet, Nothing] = | |
baseEndpoint | |
.get | |
.in(query[UUID]("id").description("The id of the pet to find")) | |
.out(jsonBody[Pet]) | |
.description("Finds a pet by id") | |
val addPet: Endpoint[(AuthToken, Pet), Error, Unit, Nothing] = | |
baseEndpoint | |
.post | |
.in(jsonBody[Pet]) | |
.description("Adds a pet") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment