Haskell combinator library for defining and serving web services.
Questions tagged [servant]
197 questions
0
votes
1 answer
How to feed a group of handlers with value fetched from Db in servant?
I'm using servant with JWT authentication. I'm trying to fetch authenticated user and pass it to handlers not to have to repeat same logic in each handler.
With a single argument function it works like a charm:
listMeters :: Entity User -> Handler…

Nachos Tolstoy
- 1
- 1
0
votes
1 answer
How to (asynchronously) consume a steaming end-point generated with servant's StreamGenerators?
The servant documentation describes how to create streaming endpoints:
type StreamAPI = "userStream" :> StreamGet NewlineFraming JSON (StreamGenerator User)
streamAPI :: Proxy StreamAPI
streamAPI = Proxy
streamUsers :: StreamGenerator User
Now the…

Damian Nadales
- 4,907
- 1
- 21
- 34
0
votes
1 answer
Cabal error `Unknown fields: build-tool-depends` trying to follow the servant tutorial
I'm trying to follow the servant tutorial and I'm running into the Cabal error Unknown fields: build-tool-depends. This is my tutorial.cabal file (I got this from servant's github repo):
name: tutorial
version: …

L42
- 3,052
- 4
- 28
- 49
0
votes
0 answers
Servant Client Query
I am getting this error:
No instance for (Show (ClientM Bittrex)) arising from a use of ‘print
While building the following code:
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE TypeOperators #-}
module Main where
import…

Jim
- 1
- 4
0
votes
1 answer
Processing a job in background with Haskell Servant
I'm building a Facebook Messenger chatbot that can process long running jobs (that may fail), and I need to respond 200 to Facebook before the job is completed.
I've tried using Pipes, but after a while I realized that I didn't know what I was…

paparga
- 11
- 1
0
votes
1 answer
Customizing the fields generated by automatic derivation of ToSchema
I have the following type:
data Device = Device { _deviceId :: DeviceId
, _deviceName :: Text
, _deviceDtype :: DType }
deriving (Show, Eq, Generic)
makeFields ''Device
$(deriveJSON…

Damian Nadales
- 4,907
- 1
- 21
- 34
0
votes
1 answer
Generating end-point descriptions in Servant
Servant provides a way to generate documentation from the API definition. However, I see no way of (informally) documenting the functionality of each end-point. For the example used in the link above, the generated documentation contains:
##…

Damian Nadales
- 4,907
- 1
- 21
- 34
0
votes
1 answer
Using a custom datatype in a Aeson record
Preface: I'm still quite a Haskell noob so forgive me if I'm missing something obvious. I'm trying to write aeson ToJSON and FromJSON instances for a record datatype with a field with a non-standard datatype (email address).
{-# LANGUAGE DataKinds…

Carolyn Knight-Serrano
- 37
- 1
- 2
0
votes
1 answer
How do I resolve a type error using Enter from the Servant library?
I'm trying to use the enter function to allow me to run my API handlers with one set of exceptions that I'll translate to Servant at a high level, but I'm having troubles with a type match.
Given this minimal set of definitions:
-- server :: Config…

Savanni D'Gerinel
- 2,379
- 17
- 27
0
votes
1 answer
Use of `get` and `toSqlKey` in persistent
I'm trying to use persistent-postgresql with servant.
I have a User model.
I want to have an endpoint that takes an id and returns the user with that id.
According to other answers I can use toSqlKey to turn an Int64 into a Key to feed to get.
My…

leighman
- 191
- 6
0
votes
0 answers
Generate a dynamic request with servant-client
If I have some Servant's API described in servant DSL, like:
type API = "some" :> QueryParam "a" Int :> QueryParam "b" Double:> Get '[JSON] Int
It has HasClient instance, so I have a client:
λ> let theClient = client (Proxy :: Proxy API)
λ> :t…

voidlizard
- 805
- 5
- 10
0
votes
0 answers
How can i access :: Hasql.Pool.Pool inside :: BasicAuthCheck User?
I usually pass :: Hasql.Pool.Pool to serve function as an argument through run as an argument from main :: IO ()
But ever since I started planning to use :: BasicAuthCheck User for authentication, I started needing :: Hasql.Pool.Pool inside ::…

Edwin Jose Palathinkal
- 635
- 5
- 12
0
votes
2 answers
Type instance and phantom type
I ran into a strange error, I cannot find a way to fix it. I’m using servant and I am trying to build a generic authentication library (no backend by default, for instance).
The code is the following:
type TokenProtect auth = AuthProtect…

lthms
- 509
- 3
- 10
0
votes
1 answer
How to redirect requests from domain.com to www.domain in Wai/Warp app?
My site is built in Haskell/Servant and Wai/Warp. I need to redirect all requests from my domain.com to www.domain.com with the the 301 or 302 status. I know I can do that with the help of Wai/Warp somehow. How exactly?
startApp :: IO ()
startApp =…

Jushiti
- 165
- 1
- 10
0
votes
1 answer
Error "empty certificate chain" in a basic haskell app
I generated a certificate in the directory of my Haskell app:
openssl genrsa -out key.pem 2048
openssl req -new -key key.pem -out certificate.csr
openssl x509 -req -in certificate.csr -signkey key.pem -out certificate.pem
and then I ran my…

Jushiti
- 165
- 1
- 10