Skip to content

Commit 31cc64b

Browse files
committed
README.md: Add overview and example
1 parent 854e3fc commit 31cc64b

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,39 @@
11
# servant-activeresource
2+
3+
[ActiveResource](https://github.com/rails/activeresource) is a Rails
4+
library for representing resources from a RESTful API as Ruby objects,
5+
with a similar interface to the Rails ActiveRecord ORM.
6+
7+
This library provides types and TH helpers for describing such APIs,
8+
and for implementing Servant-style servers to provide them.
9+
10+
```haskell
11+
{-# LANGUAGE TemplateHaskell #-}
12+
13+
import qualified Servant.ActiveResource as AR
14+
15+
newtype MyResourceId = MyResourceId Int
16+
-- Type for new values or updates to existing values. Usually
17+
-- missing an @id@ field.
18+
data MyResource = MyResource {...}
19+
-- Like MyResource, but returned from the database.
20+
data MyStoredResource = MyStoredResource {...}
21+
22+
-- The exact monad used will depend on your program. Here, we just assume
23+
-- Handler from package servant-server.
24+
instance AR.Resource MyResourceId Handler where
25+
type ResourceData MyResourceId = MyResource
26+
type StoredResourceData MyResourceId = MyStoredResource
27+
28+
-- These form the implementation of your API.
29+
listResources = ...
30+
createResource = ...
31+
readResource = ...
32+
upsertResource = ...
33+
deleteResource = ...
34+
35+
-- Record of routes, which can be spliced into a top-level handler
36+
-- via Servant.API.NamedRoutes.
37+
routes :: AR.ResourceRoutes MyResourceId (AsServerT Handler)
38+
routes = $(AR.makeResourceServerT [t|MyResourceId|])
39+
```

0 commit comments

Comments
 (0)