Comments (12)
Ah well I wrote this issue because a colleague complained about having to put the port number in the options :-)
IMO it would make more sense to put everything that is in the RFC URL in the req Url
. Otherwise why not put the protocol in the options, or the host or especially the path? If you are going to separate them then at least separate only the things that change, i.e. the path and params. Port definitely belongs with the host and protocol. IMO :)
from req.
I can see how it makes sense, but the Url
type is rather a convenient way to pass certain pieces of information (scheme, host, path) to the req
function, it does not represent a URL as per RFC.
The question to ask here: is this way of constructing a request is more convenient for end user, compared to what we have right now (options passed in the last monoid argument to req
). I would think that the current approach is more handy and flexible, keeping Url
construction relatively lightweight.
from req.
I'm also running into this issue. It's fairly often for me that URL construction happens at a different place than HTTP calls, and req
is awkward in those situations. Right now I define type HttpsUrl = (Url 'Https, Options 'Https)
and pass HttpsUrl
s around, but that's not a great long term solution.
I think it really comes down to the goal of this library. Is it to have an easy way to construct and make an HTTP request in one function call? If so it's definitely doing a great job, but isn't going to be the right choice in my case. Or is it to be a great high-level HTTP library? If that's the case it will need a URL type. It would be cool to provide a safer alternative to uri-bytestring
, but that's getting ahead of ourselves until the earlier question is answered.
from req.
Are you aware of https://hackage.haskell.org/package/modern-uri BTW?
from req.
Nope, that looks amazing. Is there a suggested way to make HTTP requests with modern-uri
?
from req.
Not yet, but I'll think about this.
from req.
Awesome, that seems like the last piece of the puzzle.
from req.
OK, I think we could have a bridge package that would allow to turn a URI
into a pair of (Url scheme, Option scheme)
like what we have for parsing of URLs from ByteString
s:
https://hackage.haskell.org/package/req-1.0.0/docs/Network-HTTP-Req.html#v:parseUrlHttp
I however do not intend to write it at this time, if you like, you can write it, it's quite trivial.
from req.
I'm currently using:
convertUriHttps :: URI -> Maybe (Url 'Https, Option scheme)
convertUriHttps = parseUrlHttps . renderBs
It would be nice if these two packages used the same URL types, but this'll do for now.
from req.
I can understand the sentiment and I considered it myself, but there are some points that prevent me from using modern-uri
in req
directly:
-
URI
frommodern-uri
is too general. It allows any scheme, not just HTTP(S) schemes. With the level of safety we want inreq
, it's not acceptable. -
URI
is not tagged at the type level withHttp
vsHttps
. -
Automatic conversion of values of types that are instances of
ToHttpApiData
toText
is super nice and the whole system of combinators for building of URIs inreq
is well-suited for what the package tries to achieve.URI
wouldn't be so good in this role.
So helper conversion functions is the best way so far to make modern-uri
and req
play nicely together, I think.
from req.
I just threw this together: https://hackage.haskell.org/package/req-url-extra. Maybe it will be useful to others. The functions are now named toUrlHttp
and toUrlHttps
.
from req.
I think we can close this. URL type provided by this library is not a general-purpose URL/URI type, but a part of API of this specific library. These things should not be confused as they serve different purposes and satisfy different requirements.
from req.
Related Issues (20)
- Make Req an instance of MonadUnliftIO HOT 2
- Cannot perform a request with url containing braces HOT 7
- Hard to pass Link header URIs back into req HOT 5
- When req fails with a StatusCodeException the body is truncated HOT 4
- Get access to the Request HOT 5
- Add `MonadMask` instance for `Req`?
- ConnectionTimeout with "req" even though "curl" and browser work just fine HOT 1
- Set a retrying limit by default for request timeouts HOT 2
- not installable on ghc 9.0.1 due to reliance on base <4.15 HOT 3
- Support retry 0.9 HOT 1
- How can I retrieve the exact URL with query parameters? Possible limitation? HOT 6
- Interface with ToForm and FromForm HOT 2
- Support for GHC 9.2 HOT 2
- Not compatible with transformers-0.6 HOT 1
- Couldn't find a way to call odata services HOT 1
- Make responses printable. HOT 1
- Hackage docs not working for 3.3.0 HOT 2
- How can I retry the request even if it errors out? HOT 2
- unexpected program termination HOT 2
- Inspecting Request Created by `req` Function HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from req.