snaplet-rest-0.1.0: snaplet-rest.cabal
name: snaplet-rest
version: 0.1.0
homepage: http://github.com/zimothy/snaplet-rest
license: MIT
license-file: LICENSE
author: Timothy Jones
maintainer: Timothy Jones <git@zimothy.com>
copyright: (c) 2013 Timothy Jones
category: Web
build-type: Simple
cabal-version: >=1.10
synopsis: REST resources for the Snap web framework
description:
REST resources for the Snap framework.
.
As an example, let's translate the following datatype into a resource.
.
> data User = User Username String Int
>
> type Username = CI String
.
We need a type to represent changes to the resource. This 'partial' type
indicates what properties to change: either the name, the age, or both.
.
> data UserPart = UserPart (Maybe String) (Maybe Int)
.
This type also acts as a search mechanism: we can search by names, ages, or
both. We can use either a username or a @UserPart@ search to find users, and
define a function to convert URL query string parameters to this search.
.
> type UserId = Either Username UserPart
>
> userIdFromParams :: Params -> Maybe UserId
.
Now we have the pieces required to define our CRUD behaviour.
.
> createUser :: User -> AppHandler ()
>
> readUser :: UserId -> AppHandler [User]
>
> updateUser :: UserId -> UserPart -> AppHandler Bool
>
> deleteUser :: UserId -> AppHandler Bool
.
If we've implemented Aeson instances, we can add JSON as a media format
without having to define these manually. Once the behaviour is attached to
the resource, it can be served in the handler.
.
> serveUser :: AppHandler ()
> serveUser = serveResource $ resource
> & addMedia jsonInstances
> & setCreate createUser
> & setRead readUser
> & setUpdate updateUser
> & setDelete deleteUser
> & setFromParams userIdFromParams
library
hs-source-dirs: src
ghc-options: -Wall
default-language: Haskell2010
default-extensions:
MultiParamTypeClasses
OverloadedStrings
other-extensions:
FlexibleInstances
IncoherentInstances
OverlappingInstances
Rank2Types
TupleSections
exposed-modules:
Snap.Snaplet.Rest
Snap.Snaplet.Rest.Config
Snap.Snaplet.Rest.FromRequest
Snap.Snaplet.Rest.Resource
other-modules:
Snap.Snaplet.Rest.Failure
Snap.Snaplet.Rest.FromRequest.Internal
Snap.Snaplet.Rest.Media
Snap.Snaplet.Rest.Options
Snap.Snaplet.Rest.Proxy
Snap.Snaplet.Rest.Resource.Builder
Snap.Snaplet.Rest.Resource.Internal
Snap.Snaplet.Rest.Resource.Media
Snap.Snaplet.Rest.Serve
build-depends:
aeson >= 0.6.2 && < 0.7,
base >= 4.6.0 && < 4.7,
blaze-builder >= 0.3.1 && < 0.4,
bytestring >= 0.10.0 && < 0.11,
case-insensitive >= 1.0.0 && < 1.1,
http-media >= 0.1.0 && < 0.2,
lens >= 3.9.0 && < 3.10,
mtl >= 2.1.2 && < 2.2,
snap >= 0.13.0 && < 0.14,
snap-accept >= 0.1.0 && < 0.2,
snap-core >= 0.9.4 && < 0.10,
text >= 0.11.3 && < 0.12,
utf8-string >= 0.3.7 && < 0.4,
xmlhtml >= 0.2.3 && < 0.3
source-repository head
type: git
location: git://github.com/zimothy/snaplet-rest.git