purescheme-wai-routing-core 0.1.0.0 → 0.1.1.0
raw patch · 6 files changed
+59/−8 lines, 6 filesdep +case-insensitivePVP ok
version bump matches the API change (PVP)
Dependencies added: case-insensitive
API changes (from Hackage documentation)
+ Network.Wai.Routing.Purescheme.Core: withIO :: IO a -> (a -> GenericApplication b) -> GenericApplication b
+ Network.Wai.Routing.Purescheme.Core.Basic: withIO :: IO a -> (a -> GenericApplication b) -> GenericApplication b
+ Network.Wai.Routing.Purescheme.Core.Header: headerValue :: ByteString -> (Maybe ByteString -> GenericApplication b) -> GenericApplication b
Files
- ChangeLog.md +5/−0
- README.md +6/−5
- purescheme-wai-routing-core.cabal +5/−3
- src/Network/Wai/Routing/Purescheme/Core.hs +2/−0
- src/Network/Wai/Routing/Purescheme/Core/Basic.hs +7/−0
- src/Network/Wai/Routing/Purescheme/Core/Header.hs +34/−0
ChangeLog.md view
@@ -1,5 +1,10 @@ # Changelog for simple-routing-core +## 0.1.1.0++* `headerValue` function to extract value from HTTP headers+* Add `withIO` which execute an IO as part of the request handling+ ## 0.1.0.0 * First implementation
README.md view
@@ -1,7 +1,8 @@ # purescheme-wai-routing-core [](https://travis-ci.org/purescheme/purescheme-wai-routing-core)+[](http://hackage.haskell.org/package/purescheme-wai-routing-core) -*The goal of purescheme is make a simple framework for building fast microservices in haskell.*+*The goal of purescheme is make a simple framework for building fast microservices and web applications in haskell.* This module provides simple routing functions for create rest APIs on top of a WAI server. @@ -56,12 +57,12 @@ - Some of them are not using the type system properly So, as Haskell is totally functional, and, based on the simplicity of an Wai `Application` (which is basically-a function that converts requests to responses, why not create functions on top of Wai `Application` that +a function that converts requests to responses), why not create functions on top of Wai `Application` that provides a functional way to implement RESTful APIs? ## Status-Currently the API is totally functionalm but the status is considered Alpha. That means, the whole API can change-in further release until we reach the beta status.+Currently the API is totally functional but the status is considered Alpha. That means, the API can change+in further release until it reachs the beta status. ## Feedback are welcome!-Please, if you feel that some functionallity is missing or something can be improve, post a issue!+Please, if you feel that some functionallity is missing or something can be improve, post an [issue](https://github.com/purescheme/purescheme-wai-routing-core/issues) or contact the author.
purescheme-wai-routing-core.cabal view
@@ -1,13 +1,13 @@ cabal-version: 1.12 --- This file has been generated from package.yaml by hpack version 0.31.2.+-- This file has been generated from package.yaml by hpack version 0.33.0. -- -- see: https://github.com/sol/hpack ----- hash: 62443a31064cb1b5d185060c9e61a90dfa3f438fa8bdae8a2ab8a84699adf924+-- hash: 5fd2f81871cfa5740b4bfc13db2062bca2707dcef39d4e444bdc5e7b2d2e9597 name: purescheme-wai-routing-core-version: 0.1.0.0+version: 0.1.1.0 synopsis: Simple Routing functions for Wai Applications description: Please see the README on GitHub at <https://github.com/purescheme/purescheme-wai-routing-core#readme> category: Web@@ -38,6 +38,7 @@ Network.Wai.Routing.Purescheme.Core.Basic Network.Wai.Routing.Purescheme.Core.Entity Network.Wai.Routing.Purescheme.Core.Entity.Json+ Network.Wai.Routing.Purescheme.Core.Header Network.Wai.Routing.Purescheme.Core.Internal Network.Wai.Routing.Purescheme.Core.Method Network.Wai.Routing.Purescheme.Core.Path@@ -51,6 +52,7 @@ aeson , base >=4.7 && <5 , bytestring+ , case-insensitive , http-media , http-types , interpolate
src/Network/Wai/Routing/Purescheme/Core.hs view
@@ -61,6 +61,8 @@ , mapResponse -- ** Requests functions , withRequest+ -- ** Utility functions+ , withIO -- * Uri path functions , path , pathSegment
src/Network/Wai/Routing/Purescheme/Core/Basic.hs view
@@ -29,6 +29,7 @@ , completeIO , mapResponse , withRequest+ , withIO ) where @@ -123,6 +124,12 @@ completeIO responseIO _ respond = do response <- responseIO respond response++-- | Execute an IO Action and pass it to the provided function+withIO :: IO a -> (a -> GenericApplication b) -> GenericApplication b+withIO theIO f req respond = do+ var <- theIO+ f var req respond -- | Maps a response type to another response type mapResponse :: (a -> b) -> GenericApplication a -> GenericApplication b
+ src/Network/Wai/Routing/Purescheme/Core/Header.hs view
@@ -0,0 +1,34 @@+-- Copyright 2020 Fernando Rincon Martin+-- +-- Licensed under the Apache License, Version 2.0 (the "License");+-- you may not use this file except in compliance with the License.+-- You may obtain a copy of the License at+-- +-- http://www.apache.org/licenses/LICENSE-2.0+-- +-- Unless required by applicable law or agreed to in writing, software+-- distributed under the License is distributed on an "AS IS" BASIS,+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+-- See the License for the specific language governing permissions and+-- limitations under the License.+-------------------------------------------------------------------------------+{-# LANGUAGE QuasiQuotes #-}+{-# LANGUAGE OverloadedStrings #-}+module Network.Wai.Routing.Purescheme.Core.Header+ ( headerValue+ )+where+ +import Network.Wai.Routing.Purescheme.Core.Basic++import Data.ByteString (ByteString)+import qualified Data.CaseInsensitive as CI+import Network.Wai (requestHeaders)++-- | Extract the value of the first HTTP request header with a given name+headerValue :: ByteString -> (Maybe ByteString -> GenericApplication b) -> GenericApplication b+headerValue name f req =+ let+ maybeValue = lookup (CI.mk name) (requestHeaders req)+ in+ f maybeValue req