Questions tagged [servant]

Haskell combinator library for defining and serving web services.

197 questions
17
votes
1 answer

How To Add a Constraint to a Type Constructor

Consider the following data type: data Get (statusCode :: Nat) Actually, it's a simplified type constructor from servant which is then used in a type-level API like this: type API = "users" :> Verb 'GET 200 '[JSON] [User] For our purposes we can…
shock_one
  • 5,845
  • 3
  • 28
  • 39
14
votes
2 answers

What does an apostrophe in front of a list ( '[Something] ) mean in Haskell?

I was reading the Servant documentation and came across this line: type UserAPI = "users" :> QueryParam "sortby" SortBy :> Get '[JSON] [User] What is the ' doing to that list?
Marcelo Lazaroni
  • 9,819
  • 3
  • 35
  • 41
10
votes
1 answer

Redirections in Servant

What's the appropriate way to make a Servant handler respond with a redirection? I am working in a navigation REST app and I would like to respond to POST requests that create resources with a redirection to the corresponding GET resource list…
Jesuspc
  • 1,664
  • 10
  • 25
9
votes
2 answers

Adding response header in Servant

I am trying to figure out how to add CORS response header in Servant (basically, set a response header "Access-Control-Allow-Origin: *"). I wrote a small test case below with addHeader function but it errors out. I will appreciate help with figuring…
Sal
  • 4,312
  • 1
  • 17
  • 26
8
votes
1 answer

How to handle pre flight OPTIONS request with Servant

I have a servant app and have looked through the following issues for my problem I am getting a 400 for preflight request with the OPTIONS…
emg184
  • 850
  • 8
  • 19
8
votes
2 answers

Handling regular form posts (application/x-www-form-urlencoded) with servant

How can I handle regular form POSTs with Servant? In particular, given an HTML form like
Solution:
and data CheckResult = Correct |…
robx
  • 2,221
  • 1
  • 14
  • 31
8
votes
4 answers

Servant Server Sent Events support

How do I define a Server-Sent Event(SSE) end point for servant. The docs don't seem to cover this case. If Servant is not designed for the realtime use case, which Haskell server framework supports SSE?
Subra
  • 105
  • 5
8
votes
1 answer

Serving Static Files With Servant / Wai

I am following this tutorial http://www.parsonsmatt.org/programming/2015/06/07/servant-persistent.html to create APIs through servant. I want to customize the server to serve static files as well but couldn't find a way to do it. I am using the…
Ecognium
  • 2,046
  • 1
  • 19
  • 35
7
votes
1 answer

CORS header ‘Access-Control-Allow-Origin’ missing in servant

using the run from Network.Wai.Handler.Warp function to server rest api run :: Port -> Application -> IO () but while doing post request, getting an error CORS header ‘Access-Control-Allow-Origin’. any idea how to overcome this in servant/haskell
khaled alomar
  • 673
  • 4
  • 25
7
votes
3 answers

Custom JSON errors for Servant-server

When using servant, I'd like to return all errors as JSON. Currently, if a request fails to parse, I see an error message like this, returned as plain text Failed reading: not a valid json value Instead I would like to return this as…
Sean Clark Hess
  • 15,859
  • 12
  • 52
  • 100
7
votes
2 answers

Deciphering DataKind type promotion in Servant library

I am trying to gork the tutorial for the servant library, a type-level web DSL. The library makes extensive use of the DataKind language extension. Early in that that tutorial we find the following line which defines a web service end point: type…
John F. Miller
  • 26,961
  • 10
  • 71
  • 121
7
votes
2 answers

Sending Generic Content-Type in Servant

I am trying to relay some ByteString back to the client (browser). The client will not know the content-type of the document being requested so I am trying to send appropriate content-type response back to the client. The document could be an image…
Ecognium
  • 2,046
  • 1
  • 19
  • 35
7
votes
1 answer

Haskell Servant and streaming

I am trying to add a functionality to my servant server that would get a file from Amazon S3 and stream it back to the user. Because files can be big I don't want to download them locally and then serve them to clients, I'd rather prefer to stream…
Alexey Raga
  • 7,457
  • 1
  • 31
  • 40
6
votes
0 answers

Is it possible to return different http codes with Servant?

I want to write API endpoint that would return different http code depending on incoming parameter and state of external world. In python, it would look like following (wsgi): def application(environ, start_response): if check_foo(): …
KAction
  • 587
  • 2
  • 10
6
votes
3 answers

Can IO actions be sequenced while keeping the logic in a pure function?

I have the following code which grabs two pages of data from a paginated API endpoint. I'd like to modify query function to keep getting pages until it finds no more data (so replace take 2 in the code below with something which looks at the API…
zoran119
  • 10,657
  • 12
  • 46
  • 88
1
2 3
13 14