@hackage / servant-activeresource

Servant endpoints compatible with Rails's ActiveResource

Latest0.2.0.0

About

Metadata

  • Last updated , by jack
  • License BSD-3-Clause
  • Categories Web Development
  • Maintained by: Bellroy Tech Team <haskell@bellroy.com>

  • Lottery factor: 2

Links

Installation

Tested Compilers

  1. 9.12.1
  2. 9.10.1
  3. 9.8.2
  4. 9.6.6
  5. 9.4.5
  6. 9.2.4
  7. 9.0.2
  8. 8.10.7

Readme

servant-activeresource

ActiveResource is a Rails library for representing resources from a RESTful API as Ruby objects, with a similar interface to the Rails ActiveRecord ORM.

This library provides types for describing such APIs, and functions to help implement Servant-style servers that provide them.

import qualified Servant.ActiveResource as AR

newtype MyResourceId = MyResourceId Int
-- Type for new values or updates to existing values. Usually
-- missing an `id` field.
data MyResource = MyResource {...}
-- Like MyResource, but returned from the database.
data MyStoredResource = MyStoredResource {...}

-- These type family instances associate your resource's ID type
-- with the data types accepted and returned by your operations and
-- by the servant-server API.
type instance ResourceData MyResourceId = MyResource
type instance StoredResourceData MyResourceId = MyStoredResource

-- Record of routes, which can passed directly to
-- 'Servant.Server.Generic.genericServe', or spliced into another
-- record of routes via 'Servant.API.NamedRoutes'.
--
-- The exact monad used will depend on your program. Here, we just
-- assume 'Handler' from package servant-server.
routes :: AR.ResourceRoutes MyResourceId AsServer
routes = AR.makeResourceRoutes ResourceOperations
  { listResources = ...
  , createResource = ...
  , readResource = ...
  , upsertResource = ...
  , deleteResource = ...
  }