Questions tagged [servant]

Haskell combinator library for defining and serving web services.

197 questions
4
votes
1 answer

Haskell Servant passing custom data to auth handler

I'm using custom monad (with reader) to easily pass data like DB pool to my handlers (before using custom monad I used to pass connection as fn argument). This is how I've defined my custom monad : newtype Controller a = Controller {…
Reygoch
  • 1,204
  • 1
  • 11
  • 24
4
votes
1 answer

Database-backed REST API with servant?

I am running into a problem setting up a simple proof of concept servant API. This is my User datatype and my API type: data User = User { id :: Int, first_name :: String, last_name :: String } deriving (Eq, Show, Generic) instance FromRow…
asg0451
  • 493
  • 4
  • 13
4
votes
1 answer

How can I get access to http headers in Servant?

I have a simple servant application with rest api: type API = "items" :> Get '[JSON] [MyData] app :: Application app = serve api server api :: Proxy API api = Proxy server :: Server API server = getItems getItems :: ExceptT ServantErr IO…
user266003
3
votes
1 answer

Haskell servant combined api implementation

I am going through the servant tutorial found here. There is a partial implementation that is left for the user to figure out what it should be. type APIFor a i = Get '[JSON] [a] :<|> ReqBody '[JSON] a :> PostNoContent :<|> Capture "id" i…
Sylvoo
  • 265
  • 2
  • 17
3
votes
1 answer

How to limit file size for multipart/form-data upload to Servant server?

The documentation at hackage.haskell.org/package/servant-multipart says about the main combinator type MultipartForm tag a following: Note that the behavior of this combinator is configurable, by using serveWith from servant-server instead of…
adius
  • 13,685
  • 7
  • 45
  • 46
3
votes
1 answer

Haskell Servant - What is the Purpose of serveWithContext and What Does it do That a ReaderT Can't?

I'm trying to understand the purpose of Servant's serveWithContext function. The documentation states that it's not a replacement for the ReaderT Monad, but I'm uncertain as to what problem it's trying to solve that isn't already addressed by…
3
votes
1 answer

Changing the web-root (or path-prefix) at runtime via servant?

I need to give the ability to change the web-root (or path-prefix) of my API via CLI arguments. If my server exposes the following API paths... /enqueue /run /cancel ...at startup it should be possible to change them to the following by passing a…
Saurabh Nanda
  • 6,373
  • 5
  • 31
  • 60
3
votes
2 answers

How to access raw request body in servant application

In a servant/wai application the request body can be obtained using a combinator e.g. ReqBody '[JSON] Book. In this case the body is extracted as a value of type Book. It is not clear how the raw request body can be accessed without converting it to…
7puns
  • 1,505
  • 1
  • 9
  • 9
3
votes
2 answers

How to define a simple RIO LogFunc without bracketing execution

I'm trying to set up logging in a RIO application; yet, I don't seem to understand the logging interface. RIO documentation encourages to define a logger and run the application as follows: withLogFunc logOptions $ \lf -> do let env = Env --…
Ulrich Schuster
  • 1,670
  • 15
  • 24
3
votes
1 answer

How can I inspect/debug the body of a servant-client's request?

Full minimal example project available here: https://github.com/chrissound/217 I've read through https://docs.servant.dev/en/v0.16/cookbook/using-free-client/UsingFreeClient.html Where I end up with: type API = "square" :> Capture "n" Int :>…
Chris Stryczynski
  • 30,145
  • 48
  • 175
  • 286
3
votes
1 answer

Correctly handle invalid query parameter in Servant

I'm following along with the Servant tutorial, and I've defined the following API type: type UsersAPI = "users" :> QueryParam "sortby" SortBy :> Get '[JSON] [UserData] data SortBy = Id | Name | Age instance FromHttpApiData SortBy where …
Tomas Aschan
  • 58,548
  • 56
  • 243
  • 402
3
votes
1 answer

How to force Servant return JSON errors instead of plain strings?

By default, Servant returns plain string requests even if the requested endpoint returns JSON $ http $S/signup email=mail@domain.com HTTP/1.1 400 Bad Request Connection: keep-alive Date: Tue, 14 Apr 2020 15:59:32 GMT Server: nginx/1.17.9…
Nik
  • 9,063
  • 7
  • 66
  • 81
3
votes
1 answer

Answer a request with 200 or 404 based on the content of `Maybe` using Servant

I'm currently trying to implement a simple web server with servant. At the moment, I have a IO (Maybe String) that I want to expose via a GET endpoint (this might be a database lookup that may or may not return a result, hence IO and Maybe). If the…
l7r7
  • 1,134
  • 1
  • 7
  • 23
3
votes
0 answers

How to add a specific representation of the request and response of the body of an HTTP request with Haskell Middleware

How can i add a specific representation of the request and response body in a request logger? I would like to be able to have some typeclass that allows me to achieve this representation. In the Network.Wai.Middleware.RequestLogger.JSON I can see…
emg184
  • 850
  • 8
  • 19
3
votes
1 answer

Serverless works locally but not when deployed

I have written a simple servant server and converted it into a lambda function that queries a MySQL db in amazon RDS. I can get it to work locally with serverless offline start however when I deploy it (serverless deploy) I get the following error…
Jimbo
  • 331
  • 1
  • 13
1 2
3
13 14