From b366507e4498888ea229cc67b84e4e2a5c5976b0 Mon Sep 17 00:00:00 2001 From: ambroslins Date: Mon, 16 Oct 2023 17:50:08 +0200 Subject: [PATCH] Update docs with list instance --- docs/src/01-hello-world.md | 12 ++++++++++++ docs/src/02-request-anatomy.md | 6 ++---- docs/src/04-other-monads.md | 7 +++---- docs/src/06-json-api-example.md | 7 +++---- docs/src/07-blog-post-example.md | 21 +++++++++------------ 5 files changed, 29 insertions(+), 24 deletions(-) diff --git a/docs/src/01-hello-world.md b/docs/src/01-hello-world.md index d34070a..d0ea0f7 100644 --- a/docs/src/01-hello-world.md +++ b/docs/src/01-hello-world.md @@ -298,6 +298,18 @@ to the value `Server m`. So we have the flexibility on DSL level but on the level of implementation to build the tree of handlers we use the same type. which makes type very simple. +### List instance for Servers +Because of the `ToServer a => ToServer [a]` instance we can omit the `mconcat` +most of the time. Meaning we can write the previous examples as: + +```haskell +server = + "api/v1/hello" /. + [ toServer helloGet + , toServer helloPost + ] +``` + ### The path type Let's discuss the `Path` type. diff --git a/docs/src/02-request-anatomy.md b/docs/src/02-request-anatomy.md index 707beb9..1d13bae 100644 --- a/docs/src/02-request-anatomy.md +++ b/docs/src/02-request-anatomy.md @@ -272,8 +272,7 @@ main = runServer 8085 server -- | Let's define a server server :: Server IO server = - "api" - /. mconcat + "api" /. -- no args, constnat output [ "hello/world" /. helloWorld , -- required query param and custom header @@ -387,8 +386,7 @@ Let's add a swagger to our server. Just add this line: server :: IO server = withSwagger def $ - "api" /. - mcomcat [ {- the rest of the code -} ] + "api" /. [ {- the rest of the code -} ] ``` Let's add this line to our example and restart the server. diff --git a/docs/src/04-other-monads.md b/docs/src/04-other-monads.md index 687a8aa..f5aa6a7 100644 --- a/docs/src/04-other-monads.md +++ b/docs/src/04-other-monads.md @@ -116,10 +116,9 @@ Our server has two routes: server :: Server App server = "counter" - /. mconcat - [ "get" /. handleGet - , "put" /. handlePut - ] + /. [ "get" /. handleGet + , "put" /. handlePut + ] ``` Let's define the `get` route: diff --git a/docs/src/06-json-api-example.md b/docs/src/06-json-api-example.md index ded3556..ce0260b 100644 --- a/docs/src/06-json-api-example.md +++ b/docs/src/06-json-api-example.md @@ -98,10 +98,9 @@ server :: Env -> Server IO server env = withSwagger def $ "api/v1/weather" - /. mconcat - [ auth - , withAuth env $: app - ] + /. [ auth + , withAuth env $: app + ] where auth = "get/auth-token" /. requestAuthToken env diff --git a/docs/src/07-blog-post-example.md b/docs/src/07-blog-post-example.md index 4afb58e..db300dd 100644 --- a/docs/src/07-blog-post-example.md +++ b/docs/src/07-blog-post-example.md @@ -97,10 +97,9 @@ server site = logRoutes $ mconcat [ "blog" - /. mconcat - [ readServer - , writeServer - ] + /. [ readServer + , writeServer + ] , defaultPage , addFavicon $ "static" /. staticFiles resourceFiles ] @@ -145,10 +144,9 @@ Let's define read-only pages for our site. readServer = mconcat [ "read" - /. mconcat - [ "post" /. handleBlogPost site - , "quote" /. handleQuote site - ] + /. [ "post" /. handleBlogPost site + , "quote" /. handleQuote site + ] , "list" /. handleListPosts site ] @@ -173,10 +171,9 @@ Let's define a route to add new blog posts to the site: -- server to write new blog posts writeServer = "write" - /. mconcat - [ toServer $ handleWriteForm site - , toServer $ handleWriteSubmit site - ] + /. [ toServer $ handleWriteForm site + , toServer $ handleWriteSubmit site + ] handleWriteForm :: Site -> Get (Page WritePost)