Last active
May 7, 2019 19:38
-
-
Save adamw/4e27922341d18212f3300f399737000c 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
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