alp comments

This commit is contained in:
akhesaCaro 2022-02-23 07:42:17 +01:00
parent 19e432c33e
commit 2defee6b26

View file

@ -133,7 +133,7 @@ import Servant.Client ( AsClientT, ClientM, client
import Servant.Client.Generic () import Servant.Client.Generic ()
import Servant.Server ( Application, ServerT ) import Servant.Server ( Application, ServerT )
import Servant.Server.Generic ( AsServerT ) import Servant.Server.Generic ( AsServer )
``` ```
@ -298,21 +298,21 @@ deleteMovieHandler _ =
And assemble them together with the record structure, which is the glue here. And assemble them together with the record structure, which is the glue here.
```haskell ```haskell
server :: ServerT MovieCatalogAPI Handler server :: API AsServer
server = server =
API API
{ version = versionHandler { version = versionHandler
, movies = moviesHandler , movies = moviesHandler
} }
moviesHandler :: MoviesAPI (AsServerT Handler) moviesHandler :: MoviesAPI AsServer
moviesHandler = moviesHandler =
MoviesAPI MoviesAPI
{ list = movieListHandler { list = movieListHandler
, movie = movieHandler , movie = movieHandler
} }
movieHandler :: MovieId -> MovieAPI (AsServerT Handler) movieHandler :: MovieId -> MovieAPI AsServer
movieHandler movieId = MovieAPI movieHandler movieId = MovieAPI
{ get = getMovieHandler movieId { get = getMovieHandler movieId
, update = updateMovieHandler movieId , update = updateMovieHandler movieId
@ -323,6 +323,8 @@ As you might have noticed, we build our handlers out of the same record types we
Remember the `mode` type parameter we saw earlier? Since we need to transform our API type into a _server_, we need to provide a server `mode`, which is `AsServerT Handler` here. Remember the `mode` type parameter we saw earlier? Since we need to transform our API type into a _server_, we need to provide a server `mode`, which is `AsServerT Handler` here.
You can alternatively use the AsServer (= AsServerT Handler) type alias. If you need to define handlers in some specific App monad from your codebase, the mode would simply be changed to AsServerT App.
Finally, we can run the server and connect the API routes to the handlers as usual: Finally, we can run the server and connect the API routes to the handlers as usual:
``` haskell ``` haskell
@ -344,7 +346,7 @@ The client, so to speak, is very easy to implement:
``` haskell ``` haskell
movieCatalogClient :: API (AsClientT ClientM) movieCatalogClient :: API (AsClientT ClientM)
movieCatalogClient = client api -- remember: api: Proxy MovieCatalogAPI movieCatalogClient = client api -- remember: api :: Proxy MovieCatalogAPI
``` ```
Have you noticed the `mode` `AsClient ClientM`? Have you noticed the `mode` `AsClient ClientM`?
@ -374,7 +376,7 @@ Done! Weve got our client!
## Conclusion ## Conclusion
We hope that you found this workbook helpful, and that you now feel more confident using the `NamedRoutes` technique. We hope that you found this cookbook helpful, and that you now feel more confident using the record-based APIs, nested or not.
If you are interested in further understanding the built-in Servant combinators, see [Structuring APIs](../structuring-apis/StructuringApis.html). If you are interested in further understanding the built-in Servant combinators, see [Structuring APIs](../structuring-apis/StructuringApis.html).