Skip to content

Instantly share code, notes, and snippets.

View dariathecracker's full-sized avatar

Daria dariathecracker

View GitHub Profile
import akka.http.scaladsl.server.Directives._
import akka.http.scaladsl.server.Route
import endpoints4s.algebra
import endpoints4s.generic.JsonSchemas
import io.scalac.lab.api.model.{Apartment, ApiError}
trait ApartmentsEndpointsDefinition extends algebra.Endpoints with algebra.JsonEntitiesFromSchemas with JsonSchemas {
sealed trait ApiError
case class NotFoundError() extends ApiError
import io.scalac.lab.api.model.Apartment
import sttp.tapir.EndpointOutput.StatusMapping
import sttp.tapir.json.circe.jsonBody
import sttp.tapir._
import sttp.model.StatusCode
class ApartmentsEndpointsDefinition {
sealed trait ApiError
case class BadRequestError() extends ApiError
import endpoints4s.Validated
import endpoints4s.algebra.Endpoints
trait QueryStringParams extends Endpoints {
private val pagingFrom = qs[Int]("from", Some("Indicates where we should start returning data from"))
private val pagingLimit = qs[Option[Int]]("limit", Some("An optional number of rows to be returned"))
val pagingQueryString: QueryString[Paging] =
(pagingFrom & pagingLimit).xmapPartial(toValidatedPaging)(x => (x.from, x.limit))
import sttp.tapir._
import sttp.tapir.Validator._
trait QueryStringParams {
private val pagingFrom = query[Int]("from")
.description("Indicates where we should start returning data from")
.example(1)
private val pagingLimit = query[Option[Int]]("limit")
.description("An optional number of rows to be returned")
.example(Some(100))
import endpoints4s.Tupler
import endpoints4s.algebra.Endpoints
trait SecuritySupport extends Endpoints {
def authenticatedRequest[I, O](request: Request[I])(implicit tupler: Tupler.Aux[I, ApiKey, O]): Request[O]
final def authenticatedEndpoint[U, O, I](request: Request[U],
response: Response[O],
docs: EndpointDocs = EndpointDocs()
import sttp.model.StatusCode.Unauthorized
import sttp.tapir._
import sttp.tapir.server._
trait SecuritySupport[F[_]] {
def authenticate(token: Option[String]): F[Either[String, ApiKey]]
val securedEndpoint: PartialServerEndpoint[ApiKey, Unit, String, Unit, Nothing, F] = endpoint
.in(auth.apiKey(header[Option[String]]("api-key")))
import akka.actor.ActorSystem
import akka.http.scaladsl.Http
import akka.http.scaladsl.server.Directives._
import akka.http.scaladsl.server.Route
import endpoints4s.akkahttp.server
import endpoints4s.openapi
import endpoints4s.openapi.model.{Info, OpenApi}
import scala.io.StdIn
import akka.actor.ActorSystem
import akka.http.scaladsl.Http
import akka.http.scaladsl.server.Directives._
import sttp.tapir.docs.openapi._
import sttp.tapir.openapi.OpenAPI
import sttp.tapir.openapi.circe.yaml._
import sttp.tapir.swagger.akkahttp.SwaggerAkka
import scala.io.StdIn
import endpoints4s.{algebra, generic}
trait ApartmentsEndpointsDefinition extends algebra.Endpoints with algebra.JsonEntitiesFromSchemas with generic.JsonSchemas {
implicit val apartmentSchema: JsonSchema[Apartment] = genericJsonSchema
val listApartments: Endpoint[Unit, Either[String, List[Apartment]]] =
endpoint(
request = get(path / "v1" / "data" / "apartments"),
response =
response(BadRequest, textResponse, Some("An error message, when something went wrong"))
import io.circe.generic.auto._
import akka.http.scaladsl.server.Route
import sttp.tapir._
import sttp.tapir.json.circe._
import sttp.tapir.server.akkahttp._
trait ApartmentsEndpointsDefinition {
val listApartments: Endpoint[Unit, String, List[Apartment], Nothing] =
endpoint