From 005dc408dc09c3b479398ebe3e92efa2cd54846e Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Sat, 17 Oct 2015 02:26:25 +0200 Subject: Working prototype --- servant/api/Thermoprint/Api.hs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 servant/api/Thermoprint/Api.hs (limited to 'servant/api/Thermoprint/Api.hs') diff --git a/servant/api/Thermoprint/Api.hs b/servant/api/Thermoprint/Api.hs new file mode 100644 index 0000000..bd5744b --- /dev/null +++ b/servant/api/Thermoprint/Api.hs @@ -0,0 +1,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] () -- cgit v1.2.3