servant-0.1: A library to generate REST-style webservices on top of scotty, handling all the boilerplate for you

Stabilityexperimental
MaintainerAlp Mestanogullari <alp@zalora.com>
Safe HaskellSafe-Inferred

Servant.Prelude

Contents

Description

Some standard REST-y operations your Resources can support out of the box.

Your type will have to implement a couple of class instances to be usable with a backend. For the scotty backend, this means having FromJSON or ToJSON instances and the appropriate toResponse implementations for the return types of your database.

Synopsis

Defining Resources

Standard operations

data Add Source

A dummy type representing an operation that adds an entry.

Instances

addWith :: Contains Add ops ~ False => (a -> c -> IO (r Add)) -> Resource c a i r e ops -> Resource c a i r e (Add : ops)Source

Make a Resource support the Add operation by using your function.

Given:

 addPerson :: PGSQL.Connection -> Person -> IO Bool

you could do:

 mkResource "persons" postgresContext noErrorHandling
   & addWith addPerson

data Delete Source

A dummy type representing an operation that deletes an entry.

Instances

deleteWith :: Contains Delete ops ~ False => (i -> c -> IO (r Delete)) -> Resource c a i r e ops -> Resource c a i r e (Delete : ops)Source

Make a Resource support the Delete operation by using your function.

Given:

 deletePerson :: PGSQL.Connection -> PersonId -> IO Bool

you could do:

 mkResource "persons" postgresContext noErrorHandling
   & deleteWith addPerson

data ListAll Source

A dummy type representing an operation that lists all entries.

Instances

listAllWith :: Contains ListAll ops ~ False => (c -> IO [a]) -> Resource c a i r e ops -> Resource c a i r e (ListAll : ops)Source

Make a Resource support the ListAll operation by using your function.

Given:

 listAllPersons :: PGSQL.Connection -> IO [Person]

you could do:

 mkResource "persons" postgresContext noErrorHandling
   & listAllWith listAllPersons

data Update Source

A dummy type representing an operation that updates an entry.

Instances

updateWith :: Contains Update ops ~ False => (i -> a -> c -> IO (r Update)) -> Resource c a i r e ops -> Resource c a i r e (Update : ops)Source

Make a Resource support the Update operation by using your function.

Given:

 updatePerson :: PGSQL.Connection -> PersonId -> Person -> IO Bool

you could do:

 mkResource "persons" postgresContext noErrorHandling
   & updateWith updatePerson

data View Source

A dummy type representing an operation that looks up an entry.

Instances

viewWith :: Contains View ops ~ False => (i -> c -> IO (Maybe a)) -> Resource c a i r e ops -> Resource c a i r e (View : ops)Source

Make a Resource support the View operation by using your function.

Given:

 viewPerson :: PGSQL.Connection -> PersonId -> IO (Maybe Person)

you could do:

 mkResource "persons" postgresContext noErrorHandling
   & viewWith viewPerson