aboutsummaryrefslogtreecommitdiff
path: root/servant/api/Thermoprint/Api.hs
blob: bd5744b8ff84b87085a167f5c8ae123d7bff1cef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
{-# LANGUAGE DataKinds, TypeOperators, DeriveGeneric #-}

module Thermoprint.Api
       ( ThermoprintApi
       ) where

import Thermoprint
import Data.Aeson
import Servant.API
import qualified Data.Text.Lazy as Text
import qualified Data.ByteString.Lazy.Char8 as ByteString
import Data.ByteString.Lazy.Char8 (ByteString)
import GHC.Generics

import Control.Monad

instance ToJSON ByteString where
  toJSON = toJSON . Text.pack . ByteString.unpack
instance FromJSON ByteString where
  parseJSON value = (ByteString.pack . Text.unpack) `liftM` parseJSON value

instance ToJSON c => ToJSON (Inline c)
instance FromJSON c => FromJSON (Inline c)

instance ToJSON c => ToJSON (Block c)
instance FromJSON c => FromJSON (Block c)

type ThermoprintApi = "print" :> Capture "printerId" Integer :> ReqBody '[JSON] (Block String) :> Post '[JSON] ()