Skip to content

Commit

Permalink
Minor code formatting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
gregorycollins committed Nov 28, 2012
1 parent c08f985 commit d5bdfdc
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions snaplets/heist/templates/docs/tutorials/snap-api.md
Expand Up @@ -54,29 +54,29 @@ echoHandler = do

The behavior of this code can be summarized with the following rules:

1. If the user requested the site's root page (http://mysite.com/), then
return a page containing the string "hello world".
2. If the user requested /foo, then return "bar".
3. If the user requested /echo/xyz, then return "xyz".
4. If the request URL begins with /static/, then look for files on disk
1. If the user requested the site's root page (`http://mysite.com/`), then
return a page containing the string `"hello world"`.
2. If the user requested `/foo`, then return `"bar"`.
3. If the user requested `/echo/xyz`, then return `"xyz"`.
4. If the request URL begins with `/static/`, then look for files on disk
matching the rest of the path and serve them.
5. If none of these match, then Snap returns a 404 page.

Let's go over each of the Snap API functions used here.

### [`dir`](http://hackage.haskell.org/packages/archive/snap-core/0.8.0/doc/html/Snap-Core.html#v:dir)
### [`dir`](http://hackage.haskell.org/packages/archive/snap-core/0.9.0/doc/html/Snap-Core.html#v:dir)

`dir` runs its action only if the request path starts with the specified
directory. You can combine successive dir calls to match more than one
subdirectory into the path.

### [`ifTop`](http://hackage.haskell.org/packages/archive/snap-core/0.8.0/doc/html/Snap-Core.html#v:ifTop)
### [`ifTop`](http://hackage.haskell.org/packages/archive/snap-core/0.9.0/doc/html/Snap-Core.html#v:ifTop)

`ifTop` only executes its argument if the client requested the root URL. Use
this for your home page. It can also be combined with the `dir` function to
define your index handler for a certain URL directory.

### [`writeBS`](http://hackage.haskell.org/packages/archive/snap-core/0.8.0/doc/html/Snap-Core.html#v:writeBS)
### [`writeBS`](http://hackage.haskell.org/packages/archive/snap-core/0.9.0/doc/html/Snap-Core.html#v:writeBS)

`writeBS` appends a strict ByteString to the response being constructed. Snap
also provides an analogous function `writeLBS` for lazy ByteStrings. You can
Expand All @@ -101,21 +101,21 @@ your site. For large sites, this could be quite noticeable. To remedy this,
Snap also provides you with the `route` function that routes requests based on the
request path in `O(log n)` time:

### [`route`](http://hackage.haskell.org/packages/archive/snap-core/0.8.0/doc/html/Snap-Core.html#v:route)
### [`route`](http://hackage.haskell.org/packages/archive/snap-core/0.9.0/doc/html/Snap-Core.html#v:route)

`route` takes a list of (route, handler) tuples and succeeds returning the
result of the associated handler of the route that matches. If no route
matches, then `route` fails and execution is passed on to `serveDirectory`.
matches, then `route` fails and execution is passed on to `serveDirectory`.

In a real application, you will want to use `route` for almost everything.
We didn't do it that way in this example because we wanted to demonstrate
more of the API.

### [`getParam`](http://hackage.haskell.org/packages/archive/snap-core/0.8.0/doc/html/Snap-Core.html#v:getParam)
### [`getParam`](http://hackage.haskell.org/packages/archive/snap-core/0.9.0/doc/html/Snap-Core.html#v:getParam)

`getParam` retrieves a GET or POST parameter from the request. In this
example, the `route` function binds a captured portion of the URL to the
parameter `echoParam` so the associated handler can make easy use of it.
parameter `echoParam` so the associated handler can make easy use of it.
`echoHandler` checks to see whether a parameter was passed and returns the
value or an error message if it didn't exist.

Expand Down

0 comments on commit d5bdfdc

Please sign in to comment.