diff --git a/Network/Wreq.hs b/Network/Wreq.hs index 9adf9dc..3ad38f5 100644 --- a/Network/Wreq.hs +++ b/Network/Wreq.hs @@ -57,6 +57,9 @@ module Network.Wreq -- ** PUT , put , putWith + -- ** PATCH + , patch + , patchWith -- ** DELETE , delete , deleteWith @@ -291,6 +294,14 @@ put url payload = putWith defaults url payload putWith :: Putable a => Options -> String -> a -> IO (Response L.ByteString) putWith opts url payload = runRead =<< preparePut opts url payload +-- | Issue a PATCH request. +patch :: Patchable a => String -> a -> IO (Response L.ByteString) +patch url payload = patchWith defaults url payload + +-- | Issue a PATCH request, using the supplied 'Options'. +patchWith :: Patchable a => Options -> String -> a -> IO (Response L.ByteString) +patchWith opts url payload = runRead =<< preparePatch opts url payload + -- | Issue an OPTIONS request. -- -- Example: diff --git a/Network/Wreq/Internal.hs b/Network/Wreq/Internal.hs index cd3dac8..642c977 100644 --- a/Network/Wreq/Internal.hs +++ b/Network/Wreq/Internal.hs @@ -17,6 +17,7 @@ module Network.Wreq.Internal , runIgnore , prepareOptions , preparePut + , preparePatch , prepareDelete , prepareMethod , preparePayloadMethod @@ -34,7 +35,7 @@ import Network.HTTP.Client.Internal (Proxy(..), Request, Response(..), addProxy) import Network.HTTP.Client.TLS (tlsManagerSettings) import Network.Wreq.Internal.Lens (setHeader) import Network.Wreq.Internal.Types (Mgr, Req(..), Run, RunHistory) -import Network.Wreq.Types (Auth(..), Options(..), Postable(..), Putable(..)) +import Network.Wreq.Types (Auth(..), Options(..), Postable(..), Patchable(..), Putable(..)) import Prelude hiding (head) import qualified Data.ByteString as S import qualified Data.ByteString.Char8 as Char8 @@ -49,7 +50,7 @@ import qualified Network.Wreq.Lens as Lens hiding (checkResponse) -- This mess allows this module to continue to load during interactive -- development in ghci :-( #if defined(VERSION_base) -import Paths_wreq (version) +import Paths_wreq_patchable (version) #else import Data.Version (Version(..)) version :: Version @@ -201,5 +202,9 @@ preparePut :: Putable a => Options -> String -> a -> IO Req preparePut opts url payload = Req (manager opts) <$> prepare (putPayload payload . (Lens.method .~ HTTP.methodPut)) opts url +preparePatch :: Patchable a => Options -> String -> a -> IO Req +preparePatch opts url payload = Req (manager opts) <$> + prepare (patchPayload payload . (Lens.method .~ HTTP.methodPatch)) opts url + prepareDelete :: Options -> String -> IO Req prepareDelete = prepareMethod HTTP.methodDelete diff --git a/Network/Wreq/Internal/Types.hs b/Network/Wreq/Internal/Types.hs index b9c2a2d..41fc9b8 100644 --- a/Network/Wreq/Internal/Types.hs +++ b/Network/Wreq/Internal/Types.hs @@ -23,6 +23,7 @@ module Network.Wreq.Internal.Types -- * Request payloads , Payload(..) , Postable(..) + , Patchable(..) , Putable(..) -- ** URL-encoded forms , FormParam(..) @@ -218,6 +219,14 @@ class Postable a where -- ^ Represent a value in the request body (and perhaps the -- headers) of a POST request. +-- | A type that can be converted into a PATCH request payload. +class Patchable a where + patchPayload :: a -> Request -> IO Request + default patchPayload :: Putable a => a -> Request -> IO Request + patchPayload = putPayload + -- ^ Represent a value in the request body (and perhaps the + -- headers) of a PATCH request. + -- | A type that can be converted into a PUT request payload. class Putable a where putPayload :: a -> Request -> IO Request diff --git a/Network/Wreq/Types.hs b/Network/Wreq/Types.hs index 91aafca..8d7f9cd 100644 --- a/Network/Wreq/Types.hs +++ b/Network/Wreq/Types.hs @@ -22,6 +22,7 @@ module Network.Wreq.Types -- * Request payloads , Payload(..) , Postable(..) + , Patchable(..) , Putable(..) -- ** URL-encoded forms , FormParam(..) @@ -67,6 +68,19 @@ instance Postable L.ByteString instance Postable Value instance Postable Encoding +-- By default if the type is Putable, we use that as patchPayload +instance Patchable Part +instance Patchable [Part] +instance Patchable [(S.ByteString, S.ByteString)] +instance Patchable (S.ByteString, S.ByteString) +instance Patchable [FormParam] +instance Patchable FormParam +instance Patchable Payload +instance Patchable S.ByteString +instance Patchable L.ByteString +instance Patchable Value +instance Patchable Encoding + instance Putable Part where putPayload a = putPayload [a] diff --git a/README.md b/README.md index 9e42295..942a329 100644 --- a/README.md +++ b/README.md @@ -1,36 +1,2 @@ -# wreq: a Haskell web client library [![Build Status](https://travis-ci.org/bos/wreq.svg)](https://travis-ci.org/bos/wreq) +# wreq-patchable: A fork of wreq that allow PATCH requests -`wreq` is a library that makes HTTP client programming in Haskell -easy. - -# Features - -* Simple but powerful `lens`-based API - -* Over 100 tests, and built on reliable libraries like [`http-client`](http://hackage.haskell.org/package/http-client/) - and [`lens`](https://lens.github.io/) - -* Session handling includes connection keep-alive and pooling, and - cookie persistence - -* Automatic decompression - -* Powerful multipart form and file upload handling - -* Support for JSON requests and responses, including navigation of - schema-less responses - -* Basic and OAuth2 bearer authentication - -* Amazon Web Services (AWS) request signing (Version 4) - -* AWS signing supports sending requests through the - [Runscope Inc.](https://www.runscope.com) Traffic Inspector - -# Tutorials - -See [the tutorials](http://www.serpentine.com/wreq/) for a quick-start. - -# Is it done? - -No! See [`TODO.md`](TODO.md) for a rather long list of ideas. diff --git a/changelog.md b/changelog.md index ceb7af5..807b1c2 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,9 @@ -*- markdown -*- +2020-04-22 1.0.0.0 + +* Fork and add PATCH support + 2019-01-25 0.5.3.2 * Compatibility with http-client >= 0.6.0 diff --git a/wreq.cabal b/wreq-patchable.cabal similarity index 82% rename from wreq.cabal rename to wreq-patchable.cabal index 5c54295..9c27f34 100644 --- a/wreq.cabal +++ b/wreq-patchable.cabal @@ -1,38 +1,16 @@ -name: wreq -version: 0.5.3.2 +name: wreq-patchable +version: 1.0.0.0 synopsis: An easy-to-use HTTP client library. description: . - A web client library that is designed for ease of use. - . - Tutorial: - . - Features include: - . - * Simple but powerful `lens`-based API - . - * A solid test suite, and built on reliable libraries like - http-client and lens - . - * Session handling includes connection keep-alive and pooling, and - cookie persistence - . - * Automatic response body decompression - . - * Powerful multipart form and file upload handling - . - * Support for JSON requests and responses, including navigation of - schema-less responses - . - * Basic and OAuth2 bearer authentication - . - * Early TLS support via the tls package + A fork of wreq + that supports HTTP PATCH requests homepage: http://www.serpentine.com/wreq -bug-reports: https://github.com/bos/wreq/issues +bug-reports: https://github.com/nitros12/wreq-patchable/issues license: BSD3 license-file: LICENSE.md -author: Bryan O'Sullivan -maintainer: bos@serpentine.com +author: Bryan O'Sullivan , Ben Simms +maintainer: ben@bensimms.moe copyright: 2014 Bryan O'Sullivan category: Web build-type: Custom @@ -97,7 +75,7 @@ library Network.Wreq.Internal.Types Network.Wreq.Lens.Machinery Network.Wreq.Lens.TH - Paths_wreq + Paths_wreq_patchable build-depends: psqueues >= 0.2, aeson >= 0.7.0.3, @@ -209,7 +187,7 @@ test-suite tests unix-compat, uuid, vector, - wreq + wreq-patchable test-suite doctests type: exitcode-stdio-1.0