Questions tagged [servant]

Haskell combinator library for defining and serving web services.

197 questions
6
votes
2 answers

Either computations in servant handler

A servant-server Handler is a newtype wrapper over an ExceptT, and has instances for MonadThrow, MonadCatch, MonadError, etc. This might be a somewhat contrived example, but it shows an issue I often face: In a handler I want to call three functions…
beta
  • 2,380
  • 21
  • 38
6
votes
1 answer

Using Authentication With a Custom Reader Monad With Servant

An API protected with Basic Authentication type SubApi = API1 :<|> API2 :<|> API3 type API = BasicAuth "foo-realm" AuthData :> SubApi supports handlers of type AuthData -> Handler a. I have a set of handlers: handler1 :: Request1 -> AuthMonad…
ewestern
  • 293
  • 2
  • 7
5
votes
1 answer

Using Servant, Selda, and SQLite together

I have been using Haskell for a year or so, and it is fantastic. I have recently started using Servant; and I would like to use an SQL-library such as Selda, so that everything is type-safe. (This is truely incredible when combined with Elm! :)…
user2633351
  • 173
  • 4
5
votes
1 answer

Haskell Servant (Client) - GET Request with headers

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…
distro.obs
  • 181
  • 9
5
votes
1 answer

Html page in Servant -- how to combine REST API and static html pages?

I have a simple hello world Servant application. I need to add some static or dynamic html pages to it. How can I do that? In the documentation it's not mentioned. Note I don't want to create a html layout in Haskell code, I want Haskell to show the…
user266003
5
votes
1 answer

How to add a prefix to all the end points in Servant?

I have kind of a hello world app in Haskell servant, here's a part of it: type API = "my_items" :> Get '[JSON] [MyItem] :<|> "my_items" :> Capture "id" Int :> Get '[JSON] MyItem -- ................... and the urls are: localhost/my_items …
Alan Coromano
  • 24,958
  • 53
  • 135
  • 205
4
votes
1 answer

Inspecting records whose fields' types are the result of type-level computations

This came up in the context of the servant library, but the issue reappears in other contexts. Servant allows you to define named routes using a record, like this: {-# LANGUAGE DataKinds #-} {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE…
danidiaz
  • 26,936
  • 4
  • 45
  • 95
4
votes
1 answer

Haskell Servant: Construct URL from API

Suppose we have this simple API: type FooAPI = "foo" :> QueryParam "age" Int :> Get '[PlainText] Text Is there a way to link type-level servant's API with a function that will generate URL for it? Like someMagicFunction :: Proxy api ->…
wspbr
  • 137
  • 4
4
votes
1 answer

Filter the parts of a Request Path which match against a Static Segment in Servant

Supposing I'm running a Servant webserver, with two endpoints, with a type looking like this: type BookAPI = "books" :> Get '[JSON] (Map Text Text) :<|> "book" :> Capture "Name" Text :> ReqBody '[JSON] (Text) :> Post '[JSON]…
Joe
  • 1,479
  • 13
  • 22
4
votes
0 answers

Haskell, Generic method of creating Html forms

I am building a site in Servant, and was wondering if it wouldn't be possible to create a Generic instance for generating input fields. What I want, is to have a class ToInputField a where toInputField :: a -> InputField Such that, an example…
Chris Wohlert
  • 610
  • 3
  • 12
4
votes
1 answer

How to handle exception within a servant handler monad?

I want to handle a database exception inside a servant handler monad. I've tried to use the try function from the Control.Exception package to be able to case match with Left exception -> throwError err422 { errBody = ... }. I'm using…
4
votes
1 answer

How can I use log-warper with Servant?

I have an application built on top of Servant, and now I want to add logging to the application. I skimmed through Haskell log packages, and I assume this one provides what I need:…
fycth
  • 3,410
  • 25
  • 37
4
votes
1 answer

Servant cookie minimal example

Can anyone please provide me with a minimal example of cookies with servant-server, wai, warp, etc.? For example, a cookie with a single field "language" with value "en" Is there an easy way like happstack-lite addCookies and lookCookieValue?
RamiroPastor
  • 1,085
  • 1
  • 7
  • 18
4
votes
1 answer

haskell webframeworks speed, GHCi vs Compiled

Today I did little benchmarking on my local machine to compare plain text speed of different Haskell web frameworks, and I noticed something strange. Almost all the frameworks that I tested, performed better when they were run from GHCi compared to…
milad zahedi
  • 787
  • 6
  • 21
4
votes
3 answers

Haskell Servant Get Current Route / URL From Handler

I'd like to get current route that corresponds to my handler. Here is mockup of my server just for reference: type ServerAPI = "route01" :> Get '[HTML] Text :<|> "route02" :> "subroute" :> Get '[HTML] Text :<|> "route03" :> Get…
Reygoch
  • 1,204
  • 1
  • 11
  • 24
1
2
3
13 14