purescript-httpurple/Library/HTTPure/Request.purs

33 lines
954 B
Haskell
Raw Normal View History

module HTTPure.Request
( Request
, fromHTTPRequest
, getURL
) where
2017-07-10 10:17:13 +00:00
import Node.HTTP as HTTP
import Node.Stream as Stream
2017-07-10 10:17:13 +00:00
-- | The Request type takes as it's parameter an effects row. It is a Record
-- | type with two fields:
-- |
-- | - `httpRequest`: The raw underlying HTTP request.
-- | - `stream`: The raw request converted to a Readable stream.
-- |
-- | Neither field is intended to be accessed directly, rather it is recommended
-- | to use the methods exported by this module.
type Request e =
{ httpRequest :: HTTP.Request
, stream :: Stream.Readable () (http :: HTTP.HTTP | e)
}
2017-07-10 10:17:13 +00:00
-- | Convert a Node.HTTP Request into a HTTPure Request.
fromHTTPRequest :: forall e. HTTP.Request -> Request e
2017-07-10 10:17:13 +00:00
fromHTTPRequest request =
{ httpRequest: request
, stream: HTTP.requestAsStream request
}
2017-07-10 10:17:13 +00:00
-- | Get the URL used to generate a Request.
getURL :: forall e. Request e -> String
getURL request = HTTP.requestURL request.httpRequest