-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#166: Add documentation to tapiro (closes #166) #167
Changes from 5 commits
db67642
7484597
6189df6
c646a28
695d806
a01f2b2
ae6cf8e
252e6f4
453b21a
bc03dcd
1edc199
73b0dd8
f318e12
c1def6c
70dc3c2
aebdf11
6da7938
a0bb44b
2c4aad5
a22e84f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -29,18 +29,53 @@ For each controller tapiro generates two files: | |||||
- `CatsEndpoints.scala` containing the HTTP api description using https://tapir-scala.readthedocs.io/ | ||||||
- `CatsHttp4sEndpoints.scala` or `CatsAkkaHttpEndpoints.scala` depeneding on the HTTP server the user is using. | ||||||
|
||||||
The resulting routes can be simply used like this (http4s example): | ||||||
```scala | ||||||
val routes = CatsHttp4sEndpoints.routes(catsImplementation) | ||||||
|
||||||
override def run(args: List[String]): IO[ExitCode] = | ||||||
BlazeServerBuilder[IO] | ||||||
.bindHttp(port, host) | ||||||
.withHttpApp(routes.orNotFound) | ||||||
.serve | ||||||
.compile | ||||||
.drain | ||||||
.as(ExitCode.Success) | ||||||
## Complete Example | ||||||
|
||||||
Here you have an example implementation of the `Cats` controller definied in the previous section: | ||||||
|
||||||
```scala mdoc | ||||||
import cats.effect._ | ||||||
|
||||||
class CatsImpl[F[_]](implicit F: Sync[F]) extends Cats[F, String] { | ||||||
override def findCutestCat(): F[Either[Error, Cat]] = F.delay(Right(Cat("Cheshire"))) | ||||||
override def doSomethingWithTheCat(catId: Int, token: String): F[Either[Error, Unit]] = F.delay(Right(())) | ||||||
} | ||||||
calippo marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
|
||||||
``` | ||||||
|
||||||
Here you have the autogenerated magic fromo tapiro (This is the content of `CatsHttp4sEndpoints.scala` it will be autogenerated). | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
```scala mdoc | ||||||
import org.http4s.HttpRoutes | ||||||
|
||||||
// ---- begins autogenerated code | ||||||
object CatsHttp4sEndpoints { | ||||||
def routes(controller: Cats[IO, String]): HttpRoutes[IO] = ??? | ||||||
} | ||||||
// ---- ends autogenerated code | ||||||
``` | ||||||
|
||||||
Here is how to run the server: | ||||||
|
||||||
```scala mdoc | ||||||
import org.http4s.server.blaze._ | ||||||
import org.http4s.implicits._ | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. serve questo import? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sì There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. magari riprovo There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. confermo che serve per There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤦♂ ok |
||||||
import cats.implicits._ | ||||||
|
||||||
object Main extends IOApp { | ||||||
val catsImpl = new CatsImpl[IO]() | ||||||
calippo marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
val routes = CatsHttp4sEndpoints.routes(catsImpl) | ||||||
|
||||||
override def run(args: List[String]): IO[ExitCode] = | ||||||
BlazeServerBuilder[IO] | ||||||
.bindHttp(8080, "localhost") | ||||||
.withHttpApp(routes.orNotFound) | ||||||
.serve | ||||||
.compile | ||||||
.drain | ||||||
.as(ExitCode.Success) | ||||||
} | ||||||
``` | ||||||
|
||||||
The resulting server can be queried as follows: | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.