Skip to content

Commit

Permalink
Merge pull request #183 from input-output-hk/KtorZ/api-any-content-type
Browse files Browse the repository at this point in the history
replace 'OctetStream' content-type in API with a 'Any' for response without content
  • Loading branch information
KtorZ committed Apr 25, 2019
2 parents 3a6143b + 89ed7b8 commit 687f125
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
7 changes: 4 additions & 3 deletions src/Cardano/Wallet/Api.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ import Servant.API
, Get
, JSON
, NoContent
, OctetStream
, PostAccepted
, Put
, QueryParam
, ReqBody
)
import Servant.Extra.ContentTypes
( Any )

type Api = Addresses :<|> Wallets :<|> Transactions

Expand Down Expand Up @@ -64,7 +65,7 @@ type Wallets =
-- | https://input-output-hk.github.io/cardano-wallet/api/#operation/deleteWallet
type DeleteWallet = "wallets"
:> Capture "walletId" (ApiT WalletId)
:> DeleteNoContent '[OctetStream] NoContent
:> DeleteNoContent '[Any] NoContent

-- | https://input-output-hk.github.io/cardano-wallet/api/#operation/getWallet
type GetWallet = "wallets"
Expand All @@ -91,7 +92,7 @@ type PutWalletPassphrase = "wallets"
:> Capture "walletId" (ApiT WalletId)
:> "passphrase"
:> ReqBody '[JSON] WalletPutPassphraseData
:> Put '[OctetStream] NoContent
:> Put '[Any] NoContent

{-------------------------------------------------------------------------------
Transactions
Expand Down
18 changes: 16 additions & 2 deletions src/Servant/Extra/ContentTypes.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ module Servant.Extra.ContentTypes
, Hash (..)
, Packed
, WithHash (..)
, Any
) where

import Prelude

import Cardano.Wallet.Binary.Packfile
( decodePackfile )
import Crypto.Hash
Expand All @@ -22,13 +25,14 @@ import Crypto.Hash.IO
( HashAlgorithm (..) )
import Data.ByteArray.Encoding
( Base (Base16), convertToBase )
import Data.List.NonEmpty
( NonEmpty (..) )
import Data.Proxy
( Proxy (..) )
import Data.Text.Encoding
( decodeUtf8 )
import Network.HTTP.Media
( (//) )
import Prelude
( (//), (/:) )
import Servant.API
( Accept (..), MimeUnrender (..), ToHttpApiData (..) )

Expand Down Expand Up @@ -95,3 +99,13 @@ instance forall a b . MimeUnrender a b => MimeUnrender (Packed a) [b] where
(Left . show)
(traverse $ mimeUnrender (Proxy :: Proxy a) . BL.fromStrict)
(decodePackfile bs)

-- | Any media type
data Any

instance Accept Any where
contentTypes _ = ("*" // "*") :|
-- We also 'conveniently' accept JSON format
[ "application" // "json"
, "application" // "json" /: ("charset", "utf-8")
]

0 comments on commit 687f125

Please sign in to comment.