About Haskell's wai

Asked 2 years ago, Updated 2 years ago, 97 views

I wanted to create an api server using wai and warp in Haskell.
I want to change the request to ByteString and pass it to the function, but it doesn't work.
Thank you for your cooperation

app::Application
app request response = response $case rawPathInfo request of
    "/"     ->htmlIndex
    "/raw" - > plainIndex
    _->function$rawPathInfo request

function::ByteString->Response
function req = responseLBS
    status200
    [("Content-Type", "text/plain")]
    req

api http haskell

2022-09-29 21:20

1 Answers

This is probably a type mismatch between the regular ByteString and the delay ByteString.
If you include each module name, you will see the following:

  • Data.ByteString.ByteString
  • Data.ByteString.Lazy.ByteString

These are different types.To do this, you can convert the return value of the function rawPathInfo in the function Data.ByteString.Lazy.fromStrict.

For example, a definition file that can be read into the interactive environment:

 {-#LANGUAGE OverloadedStrings#-}

import Network.Wai
import Network.Wai.Handler.Warp

import qualified Data.ByteString as BS
import qualified Data.ByteString.Lazy as LBS

app::Application
app request response = response $case rawPathInfo request of
        rp->function rp

function::BS.ByteString->Response
function req = responseLBS
        undefined
        [("Content-Type", "text/plain")]
        (LBS.fromStrictreq)


2022-09-29 21:20

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.