Skip to content

alunduil/collection-json.hs

Repository files navigation

collection-json

Hackage CI License GHC

Collection+JSON—Hypermedia Type tools for Haskell.

collection-json lets you encode, decode, and manipulate application/vnd.collection+json documents. The library exposes a single module, Data.CollectionJSON, with aeson ToJSON/FromJSON instances for each type defined by the spec — Collection, Item, Link, Query, Template, Datum, and Error.

Install

Add collection-json to the build-depends of your package, or install it directly:

cabal install --lib collection-json

Usage

Roundtrip a minimal collection through aeson:

{-# LANGUAGE OverloadedStrings #-}

import Data.Aeson (decode, encode)
import qualified Data.ByteString.Lazy.Char8 as BL
import Data.CollectionJSON (Collection (..))
import Data.Maybe (fromJust)
import Network.URI (parseURI)

main :: IO ()
main = do
  let href = fromJust (parseURI "http://example.com/friends/")
      c    = Collection "1.0" href [] [] [] Nothing Nothing

  BL.putStrLn (encode c)
  -- {"collection":{"href":"http://example.com/friends/","version":"1.0"}}

  print (decode (encode c) :: Maybe Collection)
  -- Just (Collection {cVersion = "1.0", cHref = ..., ...})

Full API reference on Hackage. The Collection+JSON specification is at http://amundsen.com/media-types/collection/.

Contributing

Report bugs and feature requests on the issue tracker.

For changes, fork the repository, branch from main, and open a pull request against main. PRs are squash-merged. If you'd like attribution, add yourself to the COPYRIGHT file in the same PR.

License

MIT — see LICENSE.

I am providing code in the repository to you under an open source license. Because this is my personal repository, the license you receive to my code is from me and not my employer (Facebook).

About

Collection+JSON Tools for Haskell

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

 
 
 

Contributors