on master help sign in
Misc improvements in readme and docs
commitf6c89f7edf4e7498980e93b027e5002ac2b518d2 authormrkkrp <markkarpov92@gmail.com> dateFri 9 Nov 2018, 23:16 (8 years ago) parenta9e40d9
2 files changed+41−39
Network/HTTP/Req.hs+26−24 README.md+15−15
Network/HTTP/Req.hs+26−24
@@ -24,7 +24,7 @@
2424-- What does the phrase “easy-to-use” mean? It means that the library is
2525-- designed to be beginner-friendly so it's simple to add to your monad
2626-- stack, intuitive to work with, well-documented, and does not get in your
27−-- way. Doing HTTP requests is a common task and a Haskell library for this
27+-- way. Doing HTTP requests is a common task and Haskell library for this
2828-- should be very approachable and clear to beginners, thus certain
2929-- compromises were made. For example, one cannot currently modify
3030-- 'L.ManagerSettings' of the default manager because the library always
@@ -38,7 +38,7 @@
3838-- methods like 'GET' or 'OPTIONS', and the amount of implicit assumptions
3939-- is minimized by making the user specify his\/her intentions in an
4040-- explicit form (for example, it's not possible to avoid specifying the
41−-- body or method of a request). Authentication methods that assume HTTPS
41+-- body or method of request). Authentication methods that assume HTTPS
4242-- force the user to use HTTPS at the type level. The library also carefully
4343-- hides underlying types from the lower-level @http-client@ package because
4444-- those types are not safe enough (for example 'L.Request' is an instance
@@ -50,7 +50,7 @@
5050-- your own HTTP methods, create new ways to construct the body of a
5151-- request, create new authorization options, perform a request in a
5252-- different way, and create your own methods to parse and represent a
53−-- response. As a user extends the library to satisfy his\/her special
53+-- response. As the user extends the library to satisfy his\/her special
5454-- needs, the new solutions will work just like the built-ins. However, all
5555-- of the common cases are also covered by the library out-of-the-box.
5656--
@@ -61,7 +61,7 @@
6161-- applications. For example, some people prefer throwing exceptions, while
6262-- others are concerned with purity. Just define 'handleHttpException'
6363-- accordingly when making your monad instance of 'MonadHttp' and it will
64−-- play together seamlessly. Finally, the library cuts boilerplate down
64+-- play together seamlessly. Finally, the library cuts down boilerplate
6565-- considerably, and helps you write concise, easy to read, and maintainable
6666-- code.
6767--
@@ -118,7 +118,7 @@ module Network.HTTP.Req
118118 , reqBr
119119 , req'
120120 , withReqManager
121− -- * Embedding requests into your monad
121+ -- * Embedding requests in your monad
122122 -- $embedding-requests
123123 , MonadHttp (..)
124124 , HttpConfig (..)
@@ -517,7 +517,7 @@ globalManager = unsafePerformIO $ do
517517{-# NOINLINE globalManager #-}
518518
519519----------------------------------------------------------------------------
520−-- Embedding requests into your monad
520+-- Embedding requests in your monad
521521
522522-- $embedding-requests
523523--
@@ -526,7 +526,7 @@ globalManager = unsafePerformIO $ do
526526--
527527-- When writing a library, keep your API polymorphic in terms of
528528-- 'MonadHttp', only define instance of 'MonadHttp' in final application.
529−-- Another option is to use @newtype@ wrapped monad stack and define
529+-- Another option is to use a @newtype@-wrapped monad stack and define
530530-- 'MonadHttp' for it. As of version /0.4.0/, the 'Req' monad that follows
531531-- this strategy is provided out-of-the-box (see below).
532532
@@ -779,9 +779,9 @@ instance HttpMethod PATCH where
779779class HttpMethod a where
780780
781781 -- | Type function 'AllowsBody' returns a type of kind 'CanHaveBody' which
782− -- tells the rest of the library whether the method can have a body or
783− -- not. We use the special type 'CanHaveBody' lifted to the kind level
784− -- instead of 'Bool' to get more user-friendly compiler messages.
782+ -- tells the rest of the library whether the method can have body or not.
783+ -- We use the special type 'CanHaveBody' lifted to the kind level instead
784+ -- of 'Bool' to get more user-friendly compiler messages.
785785
786786 type AllowsBody a :: CanHaveBody
787787
@@ -835,13 +835,13 @@ data Url (scheme :: Scheme) = Url Scheme (NonEmpty Text)
835835 -- NOTE The second value is the path segments in reversed order.
836836 deriving (Eq, Ord, Show, Data, Typeable, Generic)
837837
838−-- | Given host name, produce a 'Url' which have “http” as its scheme and
838+-- | Given host name, produce a 'Url' which has “http” as its scheme and
839839-- empty path. This also sets port to @80@.
840840
841841http :: Text -> Url 'Http
842842http = Url Http . pure
843843
844−-- | Given host name, produce a 'Url' which have “https” as its scheme and
844+-- | Given host name, produce a 'Url' which has “https” as its scheme and
845845-- empty path. This also sets port to @443@.
846846
847847https :: Text -> Url 'Https
@@ -871,6 +871,8 @@ infixl 5 /:
871871-- This function only parses 'Url' (scheme, host, path) and optional query
872872-- parameters that are returned as 'Option'. It does not parse method name
873873-- or authentication info from given 'ByteString'.
874+--
875+-- This function expected scheme to be “http”.
874876
875877parseUrlHttp :: ByteString -> Maybe (Url 'Http, Option scheme)
876878parseUrlHttp url' = do
@@ -878,7 +880,7 @@ parseUrlHttp url' = do
878880 (host :| path, option) <- parseUrlHelper url
879881 return (foldl (/:) (http host) path, option)
880882
881−-- | Just like 'parseUrlHttp', but expects “https” scheme.
883+-- | Just like 'parseUrlHttp', but expects the “https” scheme.
882884
883885parseUrlHttps :: ByteString -> Maybe (Url 'Https, Option scheme)
884886parseUrlHttps url' = do
@@ -933,8 +935,9 @@ instance RequestComponent (Url scheme) where
933935--
934936-- A number of options for request bodies are available. The @Content-Type@
935937-- header is set for you automatically according to the body option you use
936−-- (it's always specified in documentation for a given body option). To add
937−-- your own way to represent request body, define an instance of 'HttpBody'.
938+-- (it's always specified in the documentation for a given body option). To
939+-- add your own way to represent request body, define an instance of
940+-- 'HttpBody'.
938941
939942-- | This data type represents empty body of an HTTP request. This is the
940943-- data type to use with 'HttpMethod's that cannot have a body, as it's the
@@ -1072,16 +1075,16 @@ class HttpBody body where
10721075
10731076 getRequestBody :: body -> L.RequestBody
10741077
1075− -- | This method allows to optionally specify value of @Content-Type@
1076− -- header that should be used with particular body option. By default it
1077− -- returns 'Nothing' and so @Content-Type@ is not set.
1078+ -- | This method allows us to optionally specify the value of
1079+ -- @Content-Type@ header that should be used with particular body option.
1080+ -- By default it returns 'Nothing' and so @Content-Type@ is not set.
10781081
10791082 getRequestContentType :: body -> Maybe ByteString
10801083 getRequestContentType = const Nothing
10811084
10821085-- | The type function recognizes 'NoReqBody' as having 'NoBody', while any
1083−-- other body option 'CanHaveBody'. This forces user to use 'NoReqBody' with
1084−-- 'GET' method and other methods that should not send a body.
1086+-- other body option 'CanHaveBody'. This forces the user to use 'NoReqBody'
1087+-- with 'GET' method and other methods that should not have body.
10851088
10861089type family ProvidesBody body :: CanHaveBody where
10871090 ProvidesBody NoReqBody = 'NoBody
@@ -1119,7 +1122,7 @@ instance HttpBody body => RequestComponent (Womb "body" body) where
11191122
11201123-- $optional-parameters
11211124--
1122−-- Optional parameters to a request include things like query parameters,
1125+-- Optional parameters of request include things like query parameters,
11231126-- headers, port number, etc. All optional parameters have the type
11241127-- 'Option', which is a 'Monoid'. This means that you can use 'mempty' as
11251128-- the last argument of 'req' to specify no optional parameters, or combine
@@ -1236,8 +1239,7 @@ header
12361239 -> Option scheme
12371240header name value = withRequest (attachHeader name value)
12381241
1239−-- | A non-public helper that attaches a header with given name and content
1240−-- to a 'L.Request'.
1242+-- | Attach a header with given name and content to a 'L.Request'.
12411243--
12421244-- @since 1.1.0
12431245
@@ -1285,7 +1287,7 @@ basicAuth
12851287basicAuth = basicAuthUnsafe
12861288
12871289-- | An alternative to 'basicAuth' which works for any scheme. Note that
1288−-- using basic access authentication without SSL/TLS is vulnerable to
1290+-- using basic access authentication without SSL\/TLS is vulnerable to
12891291-- attacks. Use 'basicAuth' instead unless you know what you are doing.
12901292--
12911293-- @since 0.3.1
README.md+15−15
@@ -46,7 +46,7 @@ that just works without any fooling around.
4646What does the phrase “easy-to-use” mean? It means that the library is
4747designed to be beginner-friendly so it's simple to add to your monad stack,
4848intuitive to work with, well-documented, and does not get in your way. Doing
49−HTTP requests is a common task and a Haskell library for this should be very
49+HTTP requests is a common task and Haskell library for this should be very
5050approachable and clear to beginners, thus certain compromises were made. For
5151example, one cannot currently modify `ManagerSettings` of the default
5252manager because the library always uses the same implicit global manager for
@@ -58,7 +58,7 @@ classes of errors. For example, we have correct-by-construction URLs, it's
5858guaranteed that the user does not send the request body when using methods
5959like GET or OPTIONS, and the amount of implicit assumptions is minimized by
6060making the user specify his/her intentions in an explicit form (for example,
61−it's not possible to avoid specifying the body or method of a request).
61+it's not possible to avoid specifying the body or method of request).
6262Authentication methods that assume HTTPS force the user to use HTTPS at the
6363type level. The library also carefully hides underlying types from the
6464lower-level `http-client` package because those types are not safe enough
@@ -69,7 +69,7 @@ it will blow up at run-time).
6969HTTP without having to resort to ugly hacking. For example, it's possible to
7070define your own HTTP methods, create new ways to construct the body of a
7171request, create new authorization options, perform a request in a different
72−way, and create your own methods to parse and represent a response. As a
72+way, and create your own methods to parse and represent a response. As the
7373user extends the library to satisfy his/her special needs, the new solutions
7474will work just like the built-ins. However, all of the common cases are also
7575covered by the library out-of-the-box.
@@ -81,7 +81,7 @@ adapt easily to any particular style of writing Haskell applications. For
8181example, some people prefer throwing exceptions, while others are concerned
8282with purity. Just define `handleHttpException` accordingly when making your
8383monad instance of `MonadHttp` and it will play together seamlessly. Finally,
84−the library cuts boilerplate down considerably, and helps you write concise,
84+the library cuts down boilerplate considerably, and helps you write concise,
8585easy to read, and maintainable code.
8686
8787The library uses the following mature packages under the hood to guarantee
@@ -126,18 +126,18 @@ global implicit `Manager` (Req does the same). If I tried to frame what
126126exactly I don't like about `http-conduit` in words, then it would be “the
127127way requests are constructed”. You set, set, set instead of *being forced*
128128to declare necessary bits and *being allowed* to declare optional bits in a
129−way that their combination is certainly valid. And you parse request from a
130−string without the protection of TH that otherwise saves the day as in
131−Yesod.
129+way that their combination is certainly valid. Also, with `http-conduit` you
130+parse request from a string without the protection of TH that otherwise
131+saves the day as in Yesod.
132132
133133Then there is Wreq. `wreq` [doesn't see much development
134134lately](https://github.com/bos/wreq/issues/93). `wreq` is by itself a weird
135135library, IMO. You have functions per method—not very good, as there may be
136−new methods, like PATCH which is not new but still missing (well you have
136+new methods, like PATCH which is not new but still missing (well, you have
137137`customMethod`, but what is the point of having per-method functions if you
138138have a more general way to use any method? you should be able to just insert
139139methods in the “argument slot” of `customMethod` and end up with a more
140−general solution). Now every method function has a companion that takes
140+general solution). Now, every method function has a companion that takes
141141`Options` (like you have `get` and `getWith`). Why the duplication? Where is
142142generality and flexibility? This is not all though, because you cannot
143143really use `get` you see in the main module, because you want to have
@@ -148,12 +148,12 @@ be shared and re-used. However with the session stuff you have yet another
148148set of per-method functions like `get` and `getWith`—these are different
149149ones, to be used with sessions! Now if you have a multi-threaded app, here
150150is a surprise for you: you can't share connections between threads as
151−connections are shared only inside `withSession` friend and “session will no
152−longer be valid after that function returns”. There are valid uses for
153−sessions, but the point is that they are just too inconvenient for common
154−tasks.
151+connections are shared only inside of the `withSession` friend and “session
152+will no longer be valid after that function returns”. There are valid uses
153+for sessions, but the point is that they are just too inconvenient for
154+common tasks.
155155
156−It's funny that one client I worked for had to have his own little wrapper
156+It's funny that one client I worked for had to invent his own little wrapper
157157around `http-client` just because he could not possibly use `wreq` and
158158`http-client` and friends were too low-level. The previous paragraph is
159159extracted from a talk with a Haskell developer who works for that client. I
@@ -202,7 +202,7 @@ please submit a PR to include it in this list.
202202Issues, bugs, and questions may be reported in [the GitHub issue tracker for
203203this project](https://github.com/mrkkrp/req/issues).
204204
205−Pull requests are also welcome and will be reviewed quickly.
205+Pull requests are also welcome.
206206
207207## License
208208