Skip to content

Instantly share code, notes, and snippets.

@adamw
Last active May 15, 2019 15:26
Show Gist options
  • Save adamw/114304ad78366e5e7d80b0a413536736 to your computer and use it in GitHub Desktop.
Save adamw/114304ad78366e5e7d80b0a413536736 to your computer and use it in GitHub Desktop.

Can you use tapir with plain java?

No. tapir relies on a couple of Scala-specific features, which won't be possible to port to Java. One example is type-safety. Every time we add a new input, with a value which maps to some request part (query, header, path, ...), the type of the value what we create is extended. This is then used to verify at compile-time that the business logic function has the correct signature - takes values of appropriate types as input as returns either the error or successful output.

I’m just wondering what do you think about using Lombok annotations in Java, do you find level of control over what happens in code with such additions enough?

When we're doing projects in Java, we use Lombok. Definitely better than generating all those getters & setters. However, it's still a hack to make Java a better language. Lombok annotations give you a good level of control, but personally when possible, I simply prefer to use a better, more powerful language (such as Scala).

Does two-step filter with limit scan all "books", even if limit is defined, or it is taking all steps into account?

Yes, in this implementation we scanned all books. In reality we would probably call a database query which would do it in a more intelligent way.

Can I use tapir for calling service using given http client ?

Yes, you can generate clients. When you interpret an endpoint as a client, you get a function which, when provided with the input parameters (as specified in the description), will call the endpoint on a given URL.

What about customer contract? Is there way to generate code from/to e.g. OpenAPI?

You can generate Scala code from an OpenAPI description, but that's a different library - Twilio's Guardrail in this case. The OpenAPI representation contains less detail than the tapir representation (for example when it comes to types and codecs - how to serialise objects), so the conversion from tapir to OpenAPI is lossy (hence it's not possible to translate the other way).

Can you compose two baseEndpoints somehow?

Yes, using methods. You can create a method (a function) which takes one base endpoint and enriches is somehow - adding the necessary detail. You can then compose such enriching functions as you would with any other functions. Of course, as long as the type signatures typecheck!


Thanks for attending!

You can find tapir here: https://github.com/softwaremill/tapir And the code from the presentation here: https://github.com/softwaremill/tapir-pres-2

Other links:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment