@@ -602,21 +602,28 @@ and "serialized" into `RawRest.Async[RestResponse]`.
602602This means that macro engine looks for an implicit instance of ` AsRaw/AsReal[RawRest.Async[RestResponse], Try[R]] `
603603for 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
611611However, there are even more defaults provided: if ` R ` is serializable as ` HttpBody ` then it's automatically serializable
612612as ` 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
616616Going even further with defaults, all types serializable as ` JsonValue ` are serializable as ` HttpBody ` .
617617This effectively means that when your method returns ` Future[R] ` then you can provide serialization
618618of ` 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
621628Ultimately, if you don't want to use ` Future ` s, you may replace it with some other asynchronous wrapper type,
622629e.g. Monix Task or some IO monad.
0 commit comments