I'm trying to replicate this curl request with Haskell Servant
curl -v -H 'Accept: application/vnd.twitchtv.v5+json' \
-H 'Client-ID: someapikey' \
-X GET 'https://api.twitch.tv/kraken/clips/top?game=Overwatch&period=week&trending=false&limit=3'
Using Twitch API. Docs here
This is what I've got so far
type Game = Text
type Cursor = Text
type Language = Text
type Limit = Int
type Period = Text
type Trending = Bool
type Application = Text
type ClientID = Text
type SearchClips = "kraken"
:> "clips"
:> "top"
:> QueryParam "game" Game
:> QueryParam "cursor" Cursor
:> QueryParam "language" Language
:> QueryParam "limit" Limit
:> QueryParam "period" Period
:> QueryParam "trending" Trending
:> Header "Accept" Application
:> Header "Client-ID" ClientID
:> Get '[JSON] Search
searchClipAPI :: Proxy SearchClips
searchClipAPI = Proxy
search
:: Maybe Game
-> Maybe Cursor
-> Maybe Language
-> Maybe Limit
-> Maybe Period
-> Maybe Trending
-> Maybe Application
-> Maybe ClientID
-> ClientM Search
search = client searchClipAPI
baseURL :: BaseUrl
baseURL = BaseUrl Https "api.twitch.tv" 443 ""
And this is how I 'run' it with http-tls
runGameClipsSearchClient :: Maybe Text -> IO ()
runGameClipsSearchClient game = do
mn <- NT.newTlsManager
let args = search
game
(Just "")
(Just "en")
(Just 50)
(Just "day")
(Just False)
(Just "application/vnd.twitchtv.v5+json")
(Just "someapikey")
envClient = mkClientEnv mn baseURL
pPrint =<< runClientM args envClient
But I must be doing something wrong because I get a '404: not found' error with the haskell code but not with the curl request.
I suspect there's something wrong with my headers because when I remove the
'Accept: application/vnd.twitchtv.v5+json'
from the curl request, I get the exact same response.