Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip url-encoding #53

Closed
uzhas-sovka opened this issue Nov 8, 2018 · 5 comments
Closed

Skip url-encoding #53

uzhas-sovka opened this issue Nov 8, 2018 · 5 comments
Labels

Comments

@uzhas-sovka
Copy link

How can I skip url-encoding? For example, I'd like to keep question sign in "search?show_type".

PS. Thanks for great Hachikell (as they say in Moscow) library!

@mrkkrp
Copy link
Owner

mrkkrp commented Nov 9, 2018

I'd like to keep question sign in "search?show_type".

Then you want to have a query flag. If so, add it by using queryFlag.

@mrkkrp mrkkrp added the question label Nov 9, 2018
@uzhas-sovka
Copy link
Author

Thanks Mark, but since I'm still a novice to Haskell after 4 years of spastic education, could you just write down a snippet? The initial line goes like

bs <- req GET (https "mysite.net" /: "en" /: "hippos" /: "search?show_type=all")

@mrkkrp
Copy link
Owner

mrkkrp commented Nov 9, 2018

Here is a complete example that fetches the page as a strict ByteString:

{-# LANGUAGE OverloadedStrings #-}

module Main (main) where

import Control.Monad.IO.Class
import Data.Aeson
import Data.Default.Class
import Data.Text (Text)
import Network.HTTP.Req

main :: IO ()
main = runReq def $ do
  r <- req GET
    (https "mysite.net" /: "en" /: "hippos" /: "search")
    NoReqBody
    bsResponse
    ("show_type" =: ("all" :: Text))
  liftIO $ print (responseBody r)

@uzhas-sovka
Copy link
Author

Thanks, it works.

[Does not connected with question itself]
Mark, your library is first in Google on "Haskell https". I have just to parse 1 page. And at first it occurs that standard Haskell package does not allow to download https, only http, and then I realize I can't just put my url without any disassembling and get the result. It takes two lines in C# to do the same job.

Maybe I'm missing something in my Haskell odyssey.

@mrkkrp
Copy link
Owner

mrkkrp commented Nov 10, 2018

Mark, your library is first in Google on "Haskell https"

It's not my fault!

I have just to parse 1 page. And at first it occurs that standard Haskell package does not allow to download https, only http

I don't see why this would be the case, req allows us to use both.

and then I realize I can't just put my url without any disassembling

Well you can put it without disassembling. see:

https://hackage.haskell.org/package/req-1.2.1/docs/Network-HTTP-Req.html#v:parseUrlHttps

...and similar. Although it's not as safe. Your URL could be malformed for example. Or what if you need to assemble it from different components that change dynamically? In that case you probably going to appreciate API of the library.

It takes two lines in C# to do the same job.

General programming is different from code golf IMO. It doesn't matter much if it's 2 lines or 5 lines. What matters is correctness.

@mrkkrp mrkkrp closed this as completed Nov 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants