Questions about Spock, a Haskell web microframework.
Questions tagged [haskell-spock]
24 questions
8
votes
1 answer
How to serve static content using Spock (Haskell)?
I am running a Spock server and wanting to serve some static content.
I am using respondMiddleware function from the "Web.Spock.Action" package.
The signature is:
respondMiddleware :: Monad m => Middleware -> ActionCtxT ctx m a
I am getting…

Rishichandra Wawhal
- 419
- 3
- 10
5
votes
1 answer
How can I use an `IO String` inside a Spock request handler?
I have the following function that produces a random string of characters in multiples of 1024:
import System.Random
rchars :: Int -> [IO Char]
rchars n = map (\_ -> randomRIO ('a', 'z')) [n | n <- [0..n]] -- a wasteful "iteration"-like func
rstr…

Alex
- 8,093
- 6
- 49
- 79
3
votes
1 answer
How to serve static files using Spock and Lucid?
Getting started with web development using Haskell, Spock, and Lucid, I can't figure out how to serve my static files. In the directory of Main.hs I have /static/css/main.css, which contains just a background colour to see if the css is indeed…

Abby
- 1,610
- 3
- 19
- 35
3
votes
1 answer
Haskell: How to test a Spock app that uses wreq?
I've written a very simple app in Haskell using Spock and wreq. I want to write some tests, but I'm not sure how to do it.
All the app does is make an HTTP request to another server and translate the JSON response into a human-friendly message.…

Jesse Shieh
- 4,660
- 5
- 34
- 49
3
votes
0 answers
Haskell Spock: How to get the raw request body
The body function in Web.Spock.Action is supposed to return the raw request body. However, it just doesn't seem to be doing that:
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Data.Text.Encoding (decodeUtf8)
import Debug.Trace …

mcmayer
- 1,931
- 12
- 22
2
votes
1 answer
Building the Spock tutorial example fails
I wanted to get going with Haskell a little bit and therefore took a look at the Spock framework. To start clean, I uninstalled everything Haskell related from my Arch Linux machine and installed ghcup, Cabal and Stack using the install scripts from…

Aarkon
- 484
- 1
- 6
- 16
2
votes
0 answers
How to add a monad transformer into a Spock app?
I have a basic hello world Spock app from following the tutorial, but now I want to add my own monad transformer, FooT, into the Spock transformer stack somehow.
I found this answer, but it looks like spockT isn't really used in the latest version…

Jesse Shieh
- 4,660
- 5
- 34
- 49
2
votes
2 answers
postgres-simple - No instance for (ToRow Int) arising from a use of ‘query’
I am new to haskell and have honestly hard times with it. But it expands my thinking, so here we go.
I am trying to run a really simple Webserver that queries a Postgres DB and should return the result as JSON.
The query is absolutely…

Björn Grambow
- 368
- 1
- 14
1
vote
1 answer
How to handle `OPTIONS` in Spock?
I'm trying to init ajax request to backend which was built in spock
handling post and get request is quite easy, there are post and get from spock to handle these…

Shawn Zhang
- 1,680
- 1
- 12
- 21
1
vote
1 answer
How to stack correctly monads to finally render to html?
My goal is to feed correctly the html function (as define in Spock-core) with a HtmlT m type (ideally Html ()). In between I am performing some Network.Http.Simple requests. Apparently my knowledge of Haskell is insufficient, I didn't find the way…

user3680029
- 179
- 8
1
vote
0 answers
Reduce class constraints in haskell and inspecting persistent tables
I'm trying to setup a basic endpoint which takes an id and goes through a join table to return all joined records using persistent and spock, a working implementation looks like this.
get ("songs" /> var) $ \id -> do
song <- getRecord404 $…

SJH
- 43
- 1
- 3
1
vote
1 answer
Capturing parameters from a POST request in Spock
In the documentation of Spock, here https://www.spock.li/2015/04/19/type-safe_routing.html, it only describes how to capture parameters from a get request. I need to capture ones from a post. How can I do that?

Jodimoro
- 4,355
- 3
- 11
- 18
1
vote
1 answer
Creating a route for static assets or images in Hasekll Spock
I have this basic Spock application taken from its website:
main :: IO ()
main =
do ref <- newIORef 0
spockCfg <- defaultSpockCfg EmptySession PCNoDatabase (DummyAppState ref)
runSpock 8080 (spock spockCfg app)
app :: SpockM ()…

user7905648
- 117
- 6
1
vote
0 answers
How to deserialize a web server response into a Haskell object using a Java class
My Haskell code needs to call a Java web server. The web server will be sending a serialized Java object as a response. I have the compiled Java class but am unsure how to use it in Haskell. Is there a way to properly deserialize the response into a…

Garrett M
- 103
- 2
- 10
1
vote
1 answer
How do I use a persistent State monad with Spock?
I'm just starting out with haskell and I'm having issues with a basic "echo" REST server.
Spock looked like a nice starting place for a REST server, and I though I got the basics of the State monad, but I'm having issues understanding how to put a…

ReaperUnreal
- 970
- 7
- 19