Skip to content

tapiro could generate client code too #227

Open
@giuscri

Description

@giuscri

Given a tapir endpoint we could easily generate functions that consumers could import and call.

val booksListingEndpoint: Endpoint[(BooksFromYear, Limit, AuthToken), String, List[Book], Nothing] = endpoint
    .get
    .in(("books" / path[String]("genre") / path[Int]("year")).mapTo(BooksFromYear))
    .in(query[Int]("limit").description("Maximum number of books to retrieve"))
    .in(header[String]("X-Auth-Token"))
    .errorOut(stringBody)
    .out(jsonBody[List[Book]])

def bookListing(booksFromYear, limit, authToken)(implicit host: String, port: Int) =
    bookListingEndpoint.toSttpRequest(s"http://{host}:{port}")

Clients could call bookListing(...) triggering a call against the endpoint.

As I understand this, this is an important piece of RPC that's currently missing from tapiro. gRPC for example generates libraries out of the protobuf's.

To my understanding this is very easy to implement and adds a crazy amount of value.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions