Skip to content

Commit 9c9825c

Browse files
committed
REST docs updated
1 parent fa36d90 commit 9c9825c

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

docs/REST.md

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -602,21 +602,28 @@ and "serialized" into `RawRest.Async[RestResponse]`.
602602
This means that macro engine looks for an implicit instance of `AsRaw/AsReal[RawRest.Async[RestResponse], Try[R]]`
603603
for every HTTP method with result type `R`.
604604

605-
`RestResponse` itself is a simple class that aggregates HTTP status code and body.
605+
`RestResponse` itself is a simple class that aggregates HTTP status code, response headers and body.
606606

607-
`RestResponse` companion object defines default implicit instances of `AsRaw/Real[RawRest.Async[RestResponse], Try[Future[R]]]`
608-
which depends on implicit `AsRaw/Real[RestResponse, R]`. This effectively means that if your method returns `Future[R]` then
609-
it's enough if `R` is serializable as `RestResponse`.
607+
`DefaultRestApiCompanion` and its friends introduce implicit instances of
608+
`AsRaw/Real[RawRest.Async[RestResponse], Try[Future[R]]]` which depends on implicit `AsRaw/Real[RestResponse, R]`.
609+
This effectively means that if your method returns `Future[R]` then it's enough if `R` is serializable as `RestResponse`.
610610

611611
However, there are even more defaults provided: if `R` is serializable as `HttpBody` then it's automatically serializable
612612
as `RestResponse`. This default translation of `HttpBody` into `RestResponse` always uses 200 as a status code
613-
(or 204 for empty body). When translating `RestResponse` into `HttpBody` and response contains erroneous status code,
614-
`HttpErrorException` is thrown (which will be subsequently captured into failed `Future`).
613+
(or 204 for empty body) and empty response headers. When translating `RestResponse` into `HttpBody` and response
614+
contains erroneous status code, `HttpErrorException` is thrown (which will be subsequently captured into failed `Future`).
615615

616616
Going even further with defaults, all types serializable as `JsonValue` are serializable as `HttpBody`.
617617
This effectively means that when your method returns `Future[R]` then you can provide serialization
618618
of `R` into any of the following: `JsonValue`, `HttpBody`, `RestResponse` - depending on how much control
619-
you need.
619+
you need. Also, remember that whe using `DefaultRestApiCompanion`, `JsonValue` serialization is automatically
620+
derived from `GenCodec` instance.
621+
622+
Below is a diagram that summarizes dependencies and defaults of implicits used to serialize results of HTTP REST methods.
623+
Each arrow `Raw <-> Real` indicates that macro engine searches for an implicit instance of `AsRaw[Raw, Real]` or
624+
`AsReal[Raw, Real]` depending on whether server or client code is being materialized.
625+
626+
![REST implicits](images/REST.svg)
620627

621628
Ultimately, if you don't want to use `Future`s, you may replace it with some other asynchronous wrapper type,
622629
e.g. Monix Task or some IO monad.

docs/images/REST.svg

Lines changed: 2 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)