Skip to content

Commit

Permalink
Update docs with list instance
Browse files Browse the repository at this point in the history
  • Loading branch information
ambroslins committed Oct 16, 2023
1 parent cd9c23d commit b366507
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 24 deletions.
12 changes: 12 additions & 0 deletions docs/src/01-hello-world.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 2 additions & 4 deletions docs/src/02-request-anatomy.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
7 changes: 3 additions & 4 deletions docs/src/04-other-monads.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
7 changes: 3 additions & 4 deletions docs/src/06-json-api-example.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
21 changes: 9 additions & 12 deletions docs/src/07-blog-post-example.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,9 @@ server site =
logRoutes $
mconcat
[ "blog"
/. mconcat
[ readServer
, writeServer
]
/. [ readServer
, writeServer
]
, defaultPage
, addFavicon $ "static" /. staticFiles resourceFiles
]
Expand Down Expand Up @@ -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
]

Expand All @@ -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)

Expand Down

0 comments on commit b366507

Please sign in to comment.