Skip to content

Commit

Permalink
README.md: Add overview and example
Browse files Browse the repository at this point in the history
  • Loading branch information
endgame committed Mar 18, 2024
1 parent 854e3fc commit 31cc64b
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,39 @@
# servant-activeresource

[ActiveResource](https://github.com/rails/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.

```haskell
{-# 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|])
```

0 comments on commit 31cc64b

Please sign in to comment.