git.iko.soy/rowtype-yoga/purescript-yoga-http-api
on feat/custom-type-errors help sign in
Add Boolean parameter parsing
commit7bda3f2803972011680ee835b2691644172fe57d authorMark <mark.eibes@gmail.com> dateMon 17 Aug 2026, 21:23 (1 month ago) parent183c10e
4 files changed+11−13
spago.yaml+1−1 src/Yoga/HTTP/API/Path.purs+7 test-compile-fail/cases/WrongCaptureType.purs−12 test/Test/PublicSurfaceTest.purs+3
spago.yaml+1−1
@@ -2,7 +2,7 @@ workspace: {}
22package:
33 name: yoga-http-api
44 publish:
5− version: 0.3.3
5+ version: 0.3.4
66 license: MIT
77 location:
88 githubOwner: rowtype-yoga
src/Yoga/HTTP/API/Path.purs+7
@@ -30,6 +30,7 @@ import Data.Int as Int
3030import Data.Maybe (Maybe(..))
3131import Data.Number as Number
3232import Data.String (Pattern(..), split)
33+import Data.String as String
3334import Data.Symbol (class IsSymbol, reflectSymbol)
3435import Prim.Row as Row
3536import Record as Record
@@ -241,6 +242,12 @@ instance parseParamNumber :: ParseParam Number where
241242 Nothing -> Left $ "Expected a number but got: " <> s
242243 Just n -> Right n
243244
245+instance parseParamBoolean :: ParseParam Boolean where
246+ parseParam s = case String.toLower s of
247+ "true" -> Right true
248+ "false" -> Right false
249+ _ -> Left $ "Expected a boolean but got: " <> s
250+
244251
245252-- | Parse a URL string into a record of typed path parameters
246253-- |
test-compile-fail/cases/WrongCaptureType.pursdeleted−12
@@ -1,12 +0,0 @@
1−-- EXPECT: No type class instance was found
2−module Test.CompileFail.WrongCaptureType where
3−
4−import Data.Maybe (Maybe)
5−import Type.Proxy (Proxy(..))
6−import Yoga.HTTP.API.Path (Path, Lit, Capture, type (/), type (:), class ParsePath, parsePath)
7−
8−-- Boolean has no ParseParam instance, so parsePath should fail
9−type MyPath = Path (Lit "users" / Capture "valid" Boolean)
10−
11−test :: Proxy MyPath -> String -> Maybe { valid :: Boolean }
12−test = parsePath
test/Test/PublicSurfaceTest.purs+3
@@ -98,6 +98,9 @@ testMethodsAndPaths = describe "public methods and paths" do
9898 expectEqual (Left "Expected an integer but got: 4.2") (parseParam "4.2" :: Either String Int)
9999 expectEqual (Right 4.2) (parseParam "4.2" :: Either String Number)
100100 expectEqual (Left "Expected a number but got: nope") (parseParam "nope" :: Either String Number)
101+ expectEqual (Right true) (parseParam "true" :: Either String Boolean)
102+ expectEqual (Right false) (parseParam "FALSE" :: Either String Boolean)
103+ expectEqual (Left "Expected a boolean but got: yes") (parseParam "yes" :: Either String Boolean)
101104
102105 test "parses exact paths into correctly named captures" do
103106 expectEqual (Just {}) (parsePath (Proxy :: Proxy (Path Root)) "/")