]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/API/Types.hs
Revert b3fb1a1697d18777af6b401c132c39a5c905e129
[gargantext.git] / src / Gargantext / API / Types.hs
1 {-|
2 Module : Gargantext.API..Types
3 Description : Ngrams List Types
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
8 Portability : POSIX
9
10 -}
11
12 {-# OPTIONS_GHC -fprint-potential-instances #-}
13
14 module Gargantext.API.Types where
15
16 import Data.Aeson
17 import qualified Data.ByteString.Lazy.Char8 as BS8
18 import Data.Either (Either(..))
19 import Data.List.NonEmpty (NonEmpty ((:|)))
20 import Data.Text (Text)
21 import qualified Data.Text.Encoding as E
22 import Data.Typeable
23 import Network.HTTP.Media ((//), (/:))
24 import Prelude (($))
25 import qualified Prelude
26 import Servant
27 ( Accept(..)
28 , MimeRender(..)
29 , MimeUnrender(..) )
30
31 data HTML deriving (Typeable)
32 instance Accept HTML where
33 contentTypes _ = "text" // "html" /: ("charset", "utf-8") :| ["text" // "html"]
34 instance MimeRender HTML BS8.ByteString where
35 mimeRender _ = Prelude.id
36 instance MimeUnrender HTML BS8.ByteString where
37 mimeUnrender _ bs = Right bs
38 instance MimeRender HTML Text where
39 mimeRender _ bs = BS8.fromStrict $ E.encodeUtf8 bs
40 instance MimeUnrender HTML Text where
41 mimeUnrender _ bs = Right $ E.decodeUtf8 $ BS8.toStrict bs
42 instance {-# OVERLAPPABLE #-} ToJSON a => MimeRender HTML a where
43 mimeRender _ = encode