servant-activeresource: Servant endpoints compatible with Rails's ActiveResources

[ bsd3, library, servant, web ] [ Propose Tags ] [ Report a vulnerability ]

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 and TH helpers for describing such APIs, and for implementing Servant-style servers to provide them.


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0.0
Change log CHANGELOG.md
Dependencies aeson (>=2.1.1.0 && <2.3), base (>=4.14 && <4.20), bytestring (>=0.10.12 && <0.13), containers (>=0.6 && <0.8), servant (>=0.19 && <0.21), servant-server (>=0.19 && <0.21), template-haskell (>=2.16 && <2.22), text (>=1.2 && <1.3 || >=2.0 && <=2.2) [details]
Tested with ghc ==8.10.7 || ==9.0.2 || ==9.2.4 || ==9.4.5 || ==9.6.4 || ==9.8.2
License BSD-3-Clause
Copyright Copyright (C) 2024 Bellroy Pty Ltd
Author Bellroy Tech Team <haskell@bellroy.com>
Maintainer Bellroy Tech Team <haskell@bellroy.com>
Category Servant, Web
Home page https://github.com/bellroy/servant-activeresource
Bug tracker https://github.com/bellroy/servant-activeresource/issues
Source repo head: git clone https://github.com/bellroy/servant-activeresource.git
Uploaded by jack at 2024-07-05T05:24:24Z
Distributions NixOS:0.1.0.0
Downloads 40 total (1 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2024-07-05 [all 1 reports]

Readme for servant-activeresource-0.1.0.0

[back to package description]

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 and TH helpers for describing such APIs, and for implementing Servant-style servers to provide them.

{-# LANGUAGE TemplateHaskell #-}

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 {...}

-- The exact monad used will depend on your program. Here, we just assume
-- `Handler` from package servant-server.
instance AR.Resource MyResourceId Handler where
  type ResourceData MyResourceId = MyResource
  type StoredResourceData MyResourceId = MyStoredResource

  -- These form the implementation of your API.
  listResources = ...
  createResource = ...
  readResource = ...
  upsertResource = ...
  deleteResource = ...

-- Record of routes, which can be spliced into a top-level handler
-- via Servant.API.NamedRoutes.
routes :: AR.ResourceRoutes MyResourceId (AsServerT Handler)
routes = $(AR.makeResourceServerT [t|MyResourceId|])