Separate headers into request and response headers
- Add response header construction using records - Update tests and examples - Update doc
This commit is contained in:
@@ -119,6 +119,11 @@ main =
|
||||
|
||||
HTTPurple 🪁 has some helpers to make json parsing and validation very simple. See the [requests guide](./Requests.md) for more information.
|
||||
|
||||
## Headers
|
||||
|
||||
HTTPurple 🪁 has two separate types for headers, namely `RequestHeader` and `ResponseHeader`. `ResponseHeader` wraps `Map CaseInsensitiveString (Array String)` and therefore allows setting multiple response headers. This is useful if you e.g. want to set multiple `Set-Cookie` headers.
|
||||
Also you can create the headers by passing a record. See the [responses documentation](./Differences.md) for more information.
|
||||
|
||||
## Other improvmenets
|
||||
|
||||
* Default closing handler - A default closing handler is provided so you can just stop your server using `ctrl+x` without having to worry about anything. You can deactivate it by setting `closingHandler: NoClosingHandler` in the listen options.
|
||||
|
||||
@@ -5,7 +5,7 @@ import Prelude
|
||||
import Data.Generic.Rep (class Generic)
|
||||
import Data.Maybe (Maybe(..))
|
||||
import Effect.Console (log)
|
||||
import HTTPurple (Headers, Request, ResponseM, ServerM, header, ok', serve)
|
||||
import HTTPurple (Request, ResponseHeaders, ResponseM, ServerM, header, ok', serve)
|
||||
import Node.FS.Aff (readFile)
|
||||
import Routing.Duplex as RD
|
||||
import Routing.Duplex.Generic as RG
|
||||
@@ -23,7 +23,7 @@ route = RD.root $ RG.sum
|
||||
filePath :: String
|
||||
filePath = "./docs/Examples/BinaryResponse/circle.png"
|
||||
|
||||
responseHeaders :: Headers
|
||||
responseHeaders :: ResponseHeaders
|
||||
responseHeaders = header "Content-Type" "image/png"
|
||||
|
||||
-- | Respond with image data when run
|
||||
|
||||
@@ -3,9 +3,9 @@ module Examples.Headers.Main where
|
||||
import Prelude
|
||||
|
||||
import Data.Generic.Rep (class Generic)
|
||||
import Data.Maybe (Maybe(..))
|
||||
import Effect.Console (log)
|
||||
import HTTPurple (Headers, Request, ResponseM, ServerM, header, ok', serve, (!@))
|
||||
import HTTPurple (Request, ResponseHeaders, ResponseM, ServerM, ok', serve, (!@))
|
||||
import HTTPurple.Headers (headers)
|
||||
import Routing.Duplex as RD
|
||||
import Routing.Duplex.Generic as RG
|
||||
|
||||
@@ -19,8 +19,11 @@ route = RD.root $ RG.sum
|
||||
}
|
||||
|
||||
-- | The headers that will be included in every response.
|
||||
responseHeaders :: Headers
|
||||
responseHeaders = header "X-Example" "hello world!"
|
||||
responseHeaders :: ResponseHeaders
|
||||
responseHeaders = headers
|
||||
{ "X-Example": "hello world!"
|
||||
, "X-Example2": "hello world!"
|
||||
}
|
||||
|
||||
-- | Route to the correct handler
|
||||
router :: Request Route -> ResponseM
|
||||
|
||||
Reference in New Issue
Block a user