Learning to build APIs with Scala Tapir
Run the following commands for quick startup and check
- git clone https://github.com/butcherless/tapir-learn.git
- cd tapir-learn
- sbt
- aviation-api/reStart
- http://localhost:8080/docs
- aviation-web/reStart
- http://localhost:8081/docs
- tapir-webapp/reStart
- http://localhost:8080/docs
Sbt build tool config file
build.sbt
JVM options for Sbt
.jvmopts
Sbt version
project/build.properties
Project dependencies
project/Dependencies
Sbt plugins
project/plugins.sbt
Run Sbt build tool
sbt ⏎
sbt 2 note: the commands below are meant to be typed one at a time inside the interactive
sbtshell. If you invoke sbt from the OS shell with several bare commands in one line (e.g.sbt clean compile), sbt 2's thin client will fail to parse it (Expected whitespace character). Join them with;in a single quoted string instead:sbt "clean;compile".
Compile the application
compile or ~compile for continuous compiling
Manage the web server with Revolver plugin
reStart, reStop, reStatus, or ~reStart
Currently broken:
sbt-revolveris not inproject/plugins.sbt, soreStartfails withNot a valid key: reStart. Until it's restored, run a module's server via its assembled jar instead (also exercises theassemblytask):sbt "<module>/assembly"thenjava -jar target/out/jvm/scala-2.13.18/<module>/<module>.jar(or<jarName>fromassembly / assemblyJarNameif it differs from the module name).
Check Swagger API:
Akkaimplementation (aviation-apimodule): http://localhost:8080/docsZIOimplementation (aviation-webodule): http://localhost:8081/docs/
Check Health endpoint (Akka)
http://localhost:8080/api/v1.0/health
curl -v http://localhost:8080/api/v1.0/health | jqRun the test suites
test or ~test for continuous testing
Reload changes in build.sbt config file
reload
Clean target working directory
clean
Check dependencies with command line and browser
dependencyUpdates, dependencyBrowseTree, dependencyList, dependencyTree
Exit Sbt
CTRL + D
Rapid test cycle via continuous testing with a single suite test:
~testOnly com.cmartin.learn.api.ActuatorApiSpec
Rapid test cycle via continuous testing with a single test:
~testOnly com.cmartin.learn.api.ActuatorApiSpec -- -z "keyword"
Automated: the integration sbt subproject (integration/src/test/scala/com/cmartin/learn/SttpITSpec.scala)
runs the same checks below as real sttp requests against a running server. It's intentionally left out of
the default aviation-root aggregate (compile/test won't touch it), so run it explicitly:
- Start the server (see "Currently broken" note above for the
reStartworkaround), then sbt integration/test
Manual: module: tapir-webapp/reStart
bash command: httpie
http -v "http://localhost:8080/api/v1.0/health"http -v "http://localhost:8080/api/v1.0/transfers/1"http -v "http://localhost:8080/api/v1.0/transfers/404"http -v "http://localhost:8080/api/v1.0/transfers/500"echo '{"sender":"ES11 0182 1111 2222 3333 4444",
"receiver":"ES99 2038 9999 8888 7777 6666",
"amount":100.0,
"currency":"EUR",
"date":"2020-11-07T08:05:13.345Z",
"desc":"Viaje a Tenerife"}' \
| http -v http://localhost:8080/api/v1.0/transfersAsynchronous non-blocking appender config
Basic standard configuration
https://doc.akka.io/docs/akka/current/general/configuration.html
tapir-webapp/src/main/resources/application.conf