Changes between Version 6 and Version 7 of HackageDB/2.0/Architecture
- Timestamp:
- 08/08/10 06:37:48 (3 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
HackageDB/2.0/Architecture
v6 v7 15 15 lines of source code. 16 16 17 This is a work in progress , somewhat unorganized. Nearly everything here was17 This is a work in progress. Nearly everything here was 18 18 implemented this past summer (2010). 19 19 … … 97 97 [(String, String)]. 98 98 99 To define a basic blog post Resource, you would write (todo: link happstack docs):99 To define a basic blog post Resource, you would write: 100 100 101 101 {{{ … … 103 103 blogPost = (resourceAt "/blog/post/:id") { resourceGet = [("txt", serveBlogPost)], resourcePut = [("txt", setBlogPost)]} 104 104 105 serveBlogPost :: !DynamicPath -> !ServerPart Response105 serveBlogPost :: DynamicPath -> ServerPart Response 106 106 serveBlogPost dpath = case fromReqURI =<< lookup "id" dpath of 107 107 Nothing -> notFound . toResponse $ "Invalid number" 108 108 Just pid -> do 109 mcontents <- query $ !LookupPost pid109 mcontents <- query $ LookupPost pid 110 110 case mcontents of 111 111 Nothing -> notFound . toResponse $ "Post #" ++ show pid ++ " not found" 112 112 ok . toResponse $ contents 113 113 114 setBlogPost :: !DynamicPath -> !ServerPart Response114 setBlogPost :: DynamicPath -> ServerPart Response 115 115 setBlogPost dpath = case fromReqURI =<< lookup "id" dpath of 116 116 Nothing -> notFound . toResponse $ "Invalid number" … … 120 120 Nothing -> badRequest . toResponse $ "Bad input, couldn't find text" 121 121 Just contents -> do 122 update $ !SetPost pid contents122 update $ SetPost pid contents 123 123 ok . toResponse $ contents 124 124 }}}
