Skip to content

v1.0.0-beta-004

Compare
Choose a tag to compare
@AngelMunoz AngelMunoz released this 09 Mar 03:15
· 58 commits to main since this release

What's Changed

  • Add test project for UrlTemplates in #1
  • Add UrlMatch Utility functions to extract values from the parameters

Here's a sample of that from the new Tests project

Note: These functions are extension methods, but standard F# functions are also available.

test "UrlMatchExtensions.getParamSeqFromQuery can return a sequence of query params" {
  let template = "/api?name&age<int>&statuses"
  let url = "/api?name=john&age=30&statuses=active&statuses=inactive"

  let _, _, urlMatch =
    RouteMatcher.matchStrings template url
    |> Result.defaultWith(fun e ->
      failtestf "Expected Ok, got Error %A" e
    )

  let name = urlMatch.getFromParams<string>("name")
  let age = urlMatch.getFromParams<int>("age")

  let values = urlMatch.getParamSeqFromQuery<string>("statuses")

  let statuses = values |> ValueOption.defaultValue Seq.empty

  Expect.equal name (ValueSome "john") "name should match"

  Expect.equal age (ValueSome 30) "age should match"

  Expect.sequenceContainsOrder
    statuses
    (seq {
      "inactive"
      "active"
    })
    "statuses should match"

}```

**Full Changelog**: https://github.com/AngelMunoz/Navs/compare/v1.0.0-beta-003...v1.0.0-beta-004