Questions tagged [servant]

Haskell combinator library for defining and serving web services.

197 questions
3
votes
1 answer

Partial reverse proxy with Haskell Servant

I'm trying to build a web server in Haskell with Servant where part of the api works as a reverse proxy to another api. I found an example of how to achieve this. But it seems that it doesn't work: type API = "cat" :> Get '[JSON] Cat newtype…
worldsayshi
  • 1,788
  • 15
  • 31
3
votes
1 answer

Struggling with wiring-up a pair of type-class constrained monads within servant

Please scroll-down to read an important edit to this question Original (long-winded) question My web-app's code is written in a type-class constrained monad, which looks something like this: fetchOrderById :: (HasDatabase m) => Args -> m…
Saurabh Nanda
  • 6,373
  • 5
  • 31
  • 60
3
votes
1 answer

safeLink in Servant

Servant uses Servant.API.safeLink to generate relative URLs, but I'm running into a problem that makes me think I am misunderstanding something basic either about how to use it or about how to define Servant APIs. The minimal example I've…
Jeremy
  • 1,049
  • 1
  • 15
  • 28
3
votes
1 answer

Servant QueryParams parse error

Given the following code: newtype HelloMessage = HelloMessage { msg :: String } deriving (Generic) instance ToJSON HelloMessage type API2 = "hello" :> QueryParam "age" Int :> Get '[JSON] HelloMessage appAPI2 :: Proxy…
autumn322
  • 447
  • 3
  • 10
3
votes
1 answer

Haskell Servant Custom JSON parsing errors

Given the following Servant server: {-# LANGUAGE DataKinds #-} {-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE TypeOperators #-} module ServantSample (main) where import Data.Aeson import Data.Aeson.TH import Network.Wai import…
adlaika
  • 107
  • 1
  • 8
3
votes
1 answer

Understanding 'echo' service example API from Servant paper

The introduction of the servant paper contains the following example API type: type Echo = "echo" :> ReqBody ’[PlainText] String :> Get ’[PlainText] String I am attempting to understand this example. It appears to be defining a…
mherzl
  • 5,624
  • 6
  • 34
  • 75
3
votes
1 answer

How to do a "SELECT ... IN (SELECT ...)" using Esqueleto?

Considering the following two models and a GET /articles/:slug/comments request, I want to retrieve the comments that belong to an article, based on its slug. Article json sql=articles slug Slug title Text description Text …
3
votes
1 answer

servant a functional dependency error with `enter`

I slightly changed the app shown in the servant tutorial to make Reader monad a ReaderT, like so {-# LANGUAGE DataKinds #-} {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE…
sinan
  • 6,809
  • 6
  • 38
  • 67
3
votes
1 answer

Haskell Servant - is there a way to compose API types?

I know this isn't valid syntax, but is there a way to accomplish something like this in servant? type StandardAPI = "foo" :> Get '[JSON] Whatever type CustomAPI = StandardAPI :<|> "customroute" :> Get '[JSON] Blah in other words, composing APIs.…
daj
  • 6,962
  • 9
  • 45
  • 79
3
votes
2 answers

Using failWith with Servant and custom monad stack

I'm using Servant with custom monad stack: newtype AppHandler a = AppHandler { runHandler :: ReaderT Config (ExceptT ServantErr IO) a } deriving (Functor, Applicative, Monad, MonadReader Config, MonadError ServantErr, MonadIO) data Config =…
Bartosz
  • 3,318
  • 21
  • 31
3
votes
0 answers

How can I add the template(layout) page functionality to Haskell Servant website?

I'm looking for simple and easy way to add template or layouts functionality to a web site in servant. So when I have a few similar pages, I don't have to create a layout for each of them completely from scratch, I can create a master or layout page…
Yolanda
  • 41
  • 4
3
votes
2 answers

Represent Foreign Key Relationship in JSON using Servant and Persistent

This morning I was following along with this interesting tutorial on using Servant to build a simple API server. At the end of the tutorial, the author suggests adding a Blog type, so I figured I would give it a shot, but I got stuck trying to…
erewok
  • 7,555
  • 3
  • 33
  • 45
3
votes
1 answer

Making a request inside an API endpoint in Servant

I'm trying to build a Telegram bot using telegram-api. I haven't had an issues with that so far since I could read the tests to understand how things worked, but I've had a lot of trouble when it comes to building a webhook endpoint with Servant.…
leemeichin
  • 3,339
  • 1
  • 24
  • 31
3
votes
1 answer

Servant: upload file as multipart/form-data

What is the way to implement a file upload API with Servant? I am trying to handle "standard" multipart/form-data but cannot figure out how to declare it in Servant. This obviously doesn't work as it cannot handle multiparts: type API = "file" :>…
Alexey Raga
  • 7,457
  • 1
  • 31
  • 40
2
votes
1 answer

Combining types for a servant endpoint

Using servant, I've got a type like the following, but more complex: type MyAPI endpointTail result = "blah" :> Capture "a" A :> endpointTail :> Get '[JSON] result Which means I can do things like this: MyAPI "hello" HelloT but when I do: MyAPI…
Clinton
  • 22,361
  • 15
  • 67
  • 163