Skip to content

Instantly share code, notes, and snippets.

@adamw
Last active May 7, 2019 19:38
Show Gist options
  • Save adamw/4e27922341d18212f3300f399737000c to your computer and use it in GitHub Desktop.
Save adamw/4e27922341d18212f3300f399737000c to your computer and use it in GitHub Desktop.
val baseEndpoint: Endpoint[Unit, (StatusCode, ErrorInfo), Unit, Nothing] =
endpoint
.in("api" / "v1.0")
.errorOut(statusCode.and(jsonBody[ErrorInfo]))
val booksQueryInput: EndpointInput[BooksQuery] =
query[Option[Year]]("year")
.and(query[Option[Int]]("limit"))
.mapTo(BooksQuery)
val getBooks: Endpoint[BooksQuery, (StatusCode, ErrorInfo), List[Book], Nothing] =
baseEndpoint
.get
.in("books")
.in(booksQueryInput)
.out(jsonBody[List[Book]].example(List(Database.books.head)))
val getBookCover: Endpoint[UUID, (StatusCode, ErrorInfo), Source[ByteString, Any],
Source[ByteString, Any]] =
baseEndpoint
.get
.in("books" / path[UUID]("bookId") / "cover")
.out(streamBody[Source[ByteString, Any]](schemaFor[Array[Byte]],
MediaType.OctetStream()))
val addBook: Endpoint[(AuthToken, NewBook), (StatusCode, ErrorInfo), Unit, Nothing] =
baseEndpoint
.post
.in(auth.bearer)
.in("books")
.in(multipartBody[NewBook])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment