https://github.com/ttak0422/elmish.urlbuilder
Elm inspired URL builder. Sample Application ->
https://github.com/ttak0422/elmish.urlbuilder
elm elmish fable fsharp
Last synced: about 2 months ago
JSON representation
Elm inspired URL builder. Sample Application ->
- Host: GitHub
- URL: https://github.com/ttak0422/elmish.urlbuilder
- Owner: ttak0422
- License: apache-2.0
- Created: 2019-04-06T09:26:11.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2023-01-03T19:16:50.000Z (over 3 years ago)
- Last Synced: 2025-04-01T18:09:03.236Z (about 1 year ago)
- Topics: elm, elmish, fable, fsharp
- Language: F#
- Homepage: https://ttak0422.github.io/Elmish.UrlBuilder.Sample/public/
- Size: 544 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Elmish.UrlBuilder
[](https://badge.fury.io/nu/Fable.Elmish.UrlBuilder)
[](https://www.codacy.com/app/ttak0422/U?utm_source=github.com&utm_medium=referral&utm_content=ttak0422/U&utm_campaign=Badge_Grade)
- master
[](https://ci.appveyor.com/project/ttak0422/elmish-urlbuilder/branch/master)
[](https://travis-ci.org/ttak0422/Elmish.UrlBuilder)
- dev
[](https://ci.appveyor.com/project/ttak0422/elmish-urlbuilder/branch/dev)
[](https://travis-ci.org/ttak0422/Elmish.UrlBuilder)
## About
[**elm/url**](https://github.com/elm/url) for [**elmish/elmish**](https://github.com/elmish/elmish)
## Build
```sh
./fake.sh build
```
## Info
### URLs
```fsharp
type Url =
{ Protocol : Protocol
Host : string
Port : Option
Path : string
Query : Option
Fragment : Option }
```
```fsharp
type Protocol =
| Http
| Https
```
```fsharp
toString // Url -> string
```
```fsharp
fromString // string -> Option
// sample
fromString "https://example.com:443/"
(*
Some { Protocol = Https
Host = "example.com"
Port = Some 443
Path = "/"
Query = None
Fragment = None }
*)
fromString "https://example.com/hats?q=top%20hat"
(*
Some { Protocol = Https
Host = "example.com"
Port = None
Path = "/hats"
Query = Some "q=top%20hat"
Fragment = None }
*)
fromString "http://example.com/core/List/#map"
(*
Some { Protocol = Http
Host = "example.com"
Port = None
Path = "/core/List"
Query = None
Fragment = Some "map" }
*)
fromString "example.com:443" = None
fromString "http://tom@example.com" = None
fromString "http://#cats" = None
```
### Percent-Encoding
```fsharp
percentEncode // string -> string
// sample
percentEncode "hat" = "hat"
percentEncode "to be" = "to%20be"
percentEncode "99%" = "99%25"
percentEncode "$" = "%24"
percentEncode "¢" = "%C2%A2"
percentEncode "€" = "%E2%82%AC"
```
```fsharp
percentDecode // string -> Option
// sample
percentDecode "hat" = Some "hat"
percentDecode "to%20be" = Some "to be"
percentDecode "99%25" = Some "99%"
percentDecode "%24" = Some "$"
percentDecode "%C2%A2" = Some "¢"
percentDecode "%E2%82%AC" = Some "€"
percentDecode "%" = None
percentDecode "%XY" = None
percentDecode "%C2" = None
```
### Queries
**The following function name is different from elm/url**
- **str (in elm/url is string)**
- **i32 (in elm/url is int)**
```fsharp
type QueryPatameter = QueryPatameter of keyValue : string * string
```
```fsharp
str // string -> string -> QueryParameter
// sample
absolute [ "products" ] [ str "search" "hat" ]
(*
"/products?search=hat"
*)
absolute [ "products" ] [ str "search" "coffee table" ]
(*
"/products?search=coffee%20table"
*)
```
```fsharp
i32 // string -> int -> QueryParameter
// sample
absolute [ "products" ] [ str "search" "hat"; i32 "page" 2 ]
(*
"/products?search=hat&page=2"
*)
```
```fsharp
toQuery // QueryParameter list -> string
// sample
toQuery [ str "search" "hat" ]
(*
"?search=hat"
*)
toQuery [ str "search" "coffee table" ]
(*
"?search=coffee%20table"
*)
toQuery [ str "search" "hat"; int "page" 2 ]
(*
"?search=hat&page=2"
*)
toQuery []
(*
""
*)
```
### Builder
```fsharp
type Root =
| Absolute
| Relative
| CrossOrigin of string
```
```fsharp
abusolute // string list -> QueryParameter list -> strnig
// sample
absolute [] []
(*
"/"
*)
absolute [ "packages"; "elmish"; "elmish" ] []
(*
"/packages/elmish/elmish
*)
absolute [ "blog"; string 42 ] []
(*
"/blog/42"
*)
absolute [ "products" ] [ str "search" "hat"; i32 "page" 2 ]
(*
"/products?search=hat&page=2"
*)
```
```fsharp
relative // string list -> QueryParameter list -> string
// sample
relative [] []
(*
""
*)
relative [ "elmish"; "elmish" ] []
(*
"elmish/elmish"
*)
relative [ "blog"; string 42 ] []
(*
"blog/42"
*)
relative [ "products" ] [ str "search" "hat"; i32 "page" 2 ]
(*
"products?search=hat&page=2"
*)
```
```fsharp
crossOrigin // string -> string list -> QueryParameter list -> string
// sample
crossOrigin "https://example.com" [ "products" ] []
(*
"https://example.com/products"
*)
crossOrigin "https://example.com" [] []
(*
"https://example.com/"
*)
crossOrigin
"https://example.com:8042"
[ "over"; "there" ]
[ str "name" "ferret" ]
(*
"https://example.com:8042/over/there?name=ferret"
*)
```
```fsharp
custom // Root -> string list -> QueryParameter list -> Option -> string
// sample
custom Absolute
[ "packages"; "elmish"; "elmish"; "latest"; "String" ]
[]
(Some "length")
(*
"/packages/elmish/elmish/latest/String#length"
*)
custom Relative [ "there" ] [ str "name" "ferret" ] None
(*
"there?name=ferret"
*)
custom
(CrossOrigin "https://example.com:8042")
[ "over"; "there" ]
[ str "name" "ferret" ]
(Some "nose")
(*
"https://example.com:8042/over/there?name=ferret#nose"
*)
```