Difference between revisions of "HAppS tutorial2"

From HaskellWiki
Jump to navigation Jump to search
Line 28: Line 28:
 
====High-level description====
 
====High-level description====
   
The definitions for many of these server part primitives can be found in HAppS-HTTP/src/HAppS/Server/SimpleHTTP.hs. However, there is another set of definitions in AlternativeHTTP.hs in the same directory. There are some subtle differences between the two. Hopefully this section will eventually have a complete description of these differences.
+
Currently, many of these ServerPart primitives are defined in SimpleHTTP.hs and AlternativeHTTP.hs. AlternativeHTTP.hs is being phased in to replace SimpleHTTP.hs, so this section will focus on the definitions from AlternativeHTTP.
   
 
* dir - match a directory at the front of the URL
 
* dir - match a directory at the front of the URL
Line 57: Line 57:
 
</haskell>
 
</haskell>
   
Similar to `dir` except instead of passing a String and a list of server parts, you pass a function that returns a list of server parts.
+
Similar to dir except instead of passing a String and a list of server parts, you pass a function that returns a list of server parts.
   
 
===Error Codes===
 
===Error Codes===

Revision as of 01:44, 4 February 2008


Most of the stuff on this page refers to HAppS 0.9.1.2 or greater. This is the most recent development version at the time of this writing. There is another tutorial for HAppS 0.8.8. Start there to get a background. This page is dedicated to the things that have changed in the newer versions.

Author's Note: This page will be in various states of disrepair for awhile. I'm creating this document as I am learning HAppS, so it may reflect my inaccurate perceptions. Some of the information on this page MAY EVEN BE WRONG. If you know it's wrong, I would be grateful for your help in improving it.

HAppS is a framework for developing Internet services quickly, deploying them easily, scaling them massively, and managing them effortlessly. Web, persistence, mail, DNS and database servers are all built-in so you can focus on app development rather than integrating and babysitting lots of different servers/services (the Haskell type system keeps everything consistent).

Introduction

The basic web server framework in HAppS consists of a call to simpleHTTP that is passed a list of ServerParts that define the available pages. simpleHTTP searches through the ServerParts and returns the response generated by the first matching ServerPart. Typically ServerParts will match based on some part of the request URL.

The ServerPart is the workhorse of defining HAppS actions. The biggest goal of this document is to provide a useful guide to the ServerPart primitives that are available.


Basic ServerPart Functions

High-level description

Currently, many of these ServerPart primitives are defined in SimpleHTTP.hs and AlternativeHTTP.hs. AlternativeHTTP.hs is being phased in to replace SimpleHTTP.hs, so this section will focus on the definitions from AlternativeHTTP.

 * dir - match a directory at the front of the URL
 * path - another way to match a URL directory
 * multi - run a list of server parts
 * withData
 * withDataFn
 * anyRequest
 * withRequest
 * applyRequest
 * method
 * ok
 * fileServe
 * toResponse

dir

dir :: String -> [ServerPart m] -> ServerPart m

The first argument is matched to the first directory element in the path URL. If it matches, then the server parts in the second argument are run.

path

path :: (FromReqURI a, Monad m) => (a -> [ServerPart m]) -> ServerPart m

Similar to dir except instead of passing a String and a list of server parts, you pass a function that returns a list of server parts.

Error Codes

 * badRequest
 * unauthorizied
 * notFound
 * seeOther
 * found
 * movedPermanently
 * tempRedirect