Haskell combinator library for defining and serving web services.
Questions tagged [servant]
197 questions
2
votes
1 answer
Haskell Servant: How to deal with invalid Accept header (or ignore it completely)
I'm writing a webhook endpoint (receiving end) and don't really have control over the incoming Accept header in the request. Here's what it is:
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
I've tried Post '[JSON, HTML, PlainText]…

Saurabh Nanda
- 6,373
- 5
- 31
- 60
2
votes
1 answer
Is there an idiomatic way to do deal with this situation when two structures share some content?
I'm making a toy forum to gain familiarity with Haskell and Servant.
My API looks something like this:
type UserAPI = "messages" :> ReqBody '[JSON] Msg :> Header "X-Real-IP" String :> Post '[JSON] APIMessage
:<|> "messages" :> ReqBody…

enola
- 23
- 4
2
votes
0 answers
Using Servant.Elm and Elm.Derive with Int64 (deriving and generating definition for an unboxed type) causes an Elm syntax error
I'm trying to use Servant.Elm and Elm.Derive to generate an Elm Api from a Haskell Servant Api including Int64 which I learnt is defined as a primitive unboxed Haskell type:
data {-# CTYPE "HsInt64" #-} Int64 = I64# Int#
In the generated Elm module…

Karl Marklund
- 485
- 1
- 4
- 10
2
votes
1 answer
Haskell, Sqlite, Pools and Servant
Background
I've written a simple Servant application that stores some information in an SQLite db file. Also, I created a generic function that runs a DB query:
{-# LANGUAGE OverloadedStrings #-}
type Db m a = ReaderT SqlBackend (NoLoggingT…

LA.27
- 1,888
- 19
- 35
2
votes
1 answer
Using Warp's `testWithApplication` from Tasty
Tasty has only the function withResource to manage resources in your tests.
The function takes a resource initialization and cleanup function as arguments:
withResource :: IO a -> (a -> IO ()) -> TestTree -> TestTree
I'm trying to test a Servant…

fghibellini
- 636
- 4
- 15
2
votes
1 answer
How to lift to Servant Server type?
I am having problems with following code:
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeOperators #-}
module API where
import Data.Text
import Servant.API
import Servant
import Repository
import …

altern
- 5,829
- 5
- 44
- 72
2
votes
1 answer
How does a Servant client handle received cookies?
I want to use a Servant client to first call a login endpoint to obtain a session cookie and then make a request against an endpoint that requires cookie authentication.
The API is (simlified)
import qualified Servant as…

Ulrich Schuster
- 1,670
- 15
- 24
2
votes
1 answer
Deny Authentication in Servant.Auth with RIO
I'm trying to combine Servant authentication (servant-auth-server package) with RIO as my handler monad to avoid the ExceptT anti-pattern. However, I can't line up the types properly for handling denied authentications.
My (simplified) API endpoint…

Ulrich Schuster
- 1,670
- 15
- 24
2
votes
0 answers
Can't make Servant serve static files
Here's the entire code of the app:
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeOperators #-}
module Lib
( startApp
, app
) where
import Data.Aeson
import Data.Aeson.TH
import Network.Wai
import…

user2649762
- 541
- 3
- 13
2
votes
0 answers
Custom combinator in Servant
I have a following problem: I would like a new type of combinator in Servant (let's name it Provide): it would behave similarly to QueryParam, but instead of searching for a given param in a query string and passing it to the handler function, it…

Swordlash
- 41
- 1
- 4
2
votes
1 answer
Should I use ReaderT to pass a database connection pool around in Servant?
I am building a web API with Servant and Persistent. I plan to define some API endpoints (about 15) that use a connection pool to access the DB.
For example, one of the endpoint definitions (Handlers) is:
getUser :: ConnectionPool -> Int -> Handler…

daylily
- 876
- 5
- 11
2
votes
2 answers
How to identify required extensions for Servant
I am reading a servant tutorial but do not understand which extension is used for what parts of the code. The tutorial starts by adding ~10 extensions at the beginning of the file but the first example only requires 3. When I go and implement my own…

Daigo
- 23
- 4
2
votes
0 answers
Passing a MongoDB connection to Servant
I'm having a little bit of trouble using Servant with the MongoDB library. I am pretty new to Haskell and Servant, so I suspect my technique is wrong.
I have two endpoints one to fetch a [Event] and one to create a new Event. So the two signatures…

BBS
- 1,351
- 2
- 12
- 27
2
votes
1 answer
How to properly reduce servant API path (:>) combinator trees for GET request via browser?
Haskell Servant docs provide several examples for writing an API to serve some content with a type level DSL like this
type API = "position" :> Capture "x" Int :> Capture "y" Int :> Get '[JSON] Position
What I want to do is write a similar API that…

atis
- 881
- 5
- 22
2
votes
0 answers
How to work with generic routes and "mount" them into larger servant apps?
Concept
I've borrowed "mount" from the Rails world. Here's what I'm conceptually trying to do:
Write a mini web-app in Servant, which others can "include/mount" in larger Servant apps
They should be able to specify a "mount point" for URLs of this…

Saurabh Nanda
- 6,373
- 5
- 31
- 60