Skip to content

Commit 3194fa4

Browse files
committed
Moved all source code
... and used new Giraffe 1.0.0 release.
1 parent bb852db commit 3194fa4

File tree

14 files changed

+2655
-1
lines changed

14 files changed

+2655
-1
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto

.travis.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
language: csharp
2+
sudo: required
3+
dist: trusty
4+
5+
dotnet: 2.1.4
6+
mono:
7+
- 4.6.1
8+
- 4.8.1
9+
- 5.0.1
10+
11+
os:
12+
- linux
13+
14+
before_install:
15+
- curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
16+
- curl https://packages.microsoft.com/config/ubuntu/14.04/prod.list | sudo tee /etc/apt/sources.list.d/microsoft.list
17+
- sudo apt-get update
18+
- sudo apt-get install -y powershell
19+
20+
script:
21+
- export FrameworkPathOverride=$(dirname $(which mono))/../lib/mono/4.5/
22+
- pwsh ./build.ps1 -Release

NuGet.config

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<packageSources>
4+
<clear />
5+
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
6+
</packageSources>
7+
</configuration>

README.md

Lines changed: 98 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,99 @@
11
# Giraffe.TokenRouter
2-
Giraffe.TokenRouter
2+
3+
![Giraffe](https://raw.githubusercontent.com/giraffe-fsharp/Giraffe/master/giraffe.png)
4+
5+
Alternative routing API for Giraffe web applications which is aimed at maximum performance.
6+
7+
[![NuGet Info](https://buildstats.info/nuget/Giraffe.TokenRouter?includePreReleases=true)](https://www.nuget.org/packages/Giraffe.TokenRouter/)
8+
9+
| Windows | Linux |
10+
| :------ | :---- |
11+
| [![Windows Build status](https://ci.appveyor.com/api/projects/status/914030ec0lrc0vti/branch/develop?svg=true)](https://ci.appveyor.com/project/dustinmoris/giraffe-tokenrouter/branch/develop) | [![Linux Build status](https://travis-ci.org/giraffe-fsharp/Giraffe.TokenRouter.svg?branch=develop)](https://travis-ci.org/giraffe-fsharp/Giraffe.TokenRouter/builds?branch=develop) |
12+
| [![Windows Build history](https://buildstats.info/appveyor/chart/dustinmoris/giraffe-tokenrouter?branch=develop&includeBuildsFromPullRequest=false)](https://ci.appveyor.com/project/dustinmoris/giraffe-tokenrouter/history?branch=develop) | [![Linux Build history](https://buildstats.info/travisci/chart/giraffe-fsharp/Giraffe.TokenRouter?branch=develop&includeBuildsFromPullRequest=false)](https://travis-ci.org/giraffe-fsharp/Giraffe.TokenRouter/builds?branch=develop) |
13+
14+
## Table of contents
15+
16+
- [Documentation](#documentation)
17+
- [Nightly builds and NuGet feed](#nightly-builds-and-nuget-feed)
18+
- [More information](#more-information)
19+
- [License](#license)
20+
21+
## Documentation
22+
23+
The `Giraffe.TokenRouter` module adds alternative `HttpHandler` functions to route incoming HTTP requests through a basic [Radix Tree](https://en.wikipedia.org/wiki/Radix_tree). Several routing handlers (e.g.: `routef` and `subRoute`) have been overridden in such a way that path matching and value parsing are significantly faster than using the basic `choose` function.
24+
25+
This implementation assumes that additional memory and compilation time is not an issue. If speed and performance of parsing and path matching is required then the `Giraffe.TokenRouter` is the preferred option.
26+
27+
### router
28+
29+
The base of all routing decisions is a `router` function instead of the default `choose` function when using the `Giraffe.TokenRouter` module.
30+
31+
The `router` HttpHandler takes two arguments, a `HttpHandler` to execute when no route can be matched (typical 404 Not Found handler) and secondly a list of all routing functions.
32+
33+
#### Example:
34+
35+
Defining a basic router and routes
36+
37+
```fsharp
38+
let notFound = setStatusCode 404 >=> text "Not found"
39+
let app =
40+
router notFound [
41+
route "/" (text "index")
42+
route "/about" (text "about")
43+
]
44+
```
45+
46+
### routing functions
47+
48+
When using the `Giraffe.TokenRouter` module the main routing functions have been slightly overridden to match the alternative (speed improved) implementation.
49+
50+
The `route` and `routef` handlers work the exact same way as before, except that the continuation handler needs to be enclosed in parentheses or captured by the `<|` or `=>` operators.
51+
52+
The http handlers `GET`, `POST`, `PUT` and `DELETE` are functions which take a list of nested http handler functions similar to before.
53+
54+
The `subRoute` handler has been altered in order to accept an additional parameter of child routing functions. All child routing functions will presume that the given sub path has been prepended.
55+
56+
#### Example:
57+
58+
Defining a basic router and routes
59+
60+
```fsharp
61+
let notFound = setStatusCode 404 >=> text "Not found"
62+
let app =
63+
router notFound [
64+
route "/" (text "index")
65+
route "/about" (text "about")
66+
routef "parsing/%s/%i" (fun (s,i) -> text (sprintf "Recieved %s & %i" s i))
67+
subRoute "/api" [
68+
GET [
69+
route "/" (text "api index")
70+
route "/about" (text "api about")
71+
subRoute "/v2" [
72+
route "/" (text "api v2 index")
73+
route "/about" (text "api v2 about")
74+
]
75+
]
76+
77+
]
78+
]
79+
```
80+
81+
## Nightly builds and NuGet feed
82+
83+
All official Giraffe packages are published to the official and public NuGet feed.
84+
85+
Unofficial builds (such as pre-release builds from the `develop` branch and pull requests) produce unofficial pre-release NuGet packages which can be pulled from the project's public NuGet feed on AppVeyor:
86+
87+
```
88+
https://ci.appveyor.com/nuget/giraffe-tokenrouter
89+
```
90+
91+
If you add this source to your NuGet CLI or project settings then you can pull unofficial NuGet packages for quick feature testing or urgent hot fixes.
92+
93+
## More information
94+
95+
For more information about Giraffe, how to set up a development environment, contribution guidelines and more please visit the [main documentation](https://github.com/giraffe-fsharp/Giraffe/blob/master/DOCUMENTATION.md) page.
96+
97+
## License
98+
99+
[Apache 2.0](https://raw.githubusercontent.com/giraffe-fsharp/Giraffe.TokenRouter/master/LICENSE)

RELEASE_NOTES.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Release Notes
2+
=============
3+
4+
## 0.1.0-beta-100
5+
6+
- Moved `Giraffe.TokenRouter` into its own repository with its own release cycle and NuGet package deployment.
7+
8+
## 0.1.0-beta-100 and before
9+
10+
Previous releases of this library were documented in [Giraffe's release notes](https://github.com/giraffe-fsharp/Giraffe/blob/master/RELEASE_NOTES.md).

appveyor.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
version: 0.1.0-{build}
2+
image: Visual Studio 2017
3+
environment:
4+
DOTNET_CLI_TELEMETRY_OPTOUT: 1
5+
init:
6+
- git config --global core.autocrlf true
7+
build: off
8+
build_script:
9+
- ps: .\build.ps1 -Release -Pack
10+
test: off
11+
artifacts:
12+
- path: '**\Giraffe.*.nupkg'
13+
name: Giraffe NuGet packages
14+
nuget:
15+
account_feed: false
16+
project_feed: true
17+
deploy:
18+
provider: NuGet
19+
api_key:
20+
secure: +XDgIu4Tmln7LKedNmQgMFnyKTxxuCKFRK3V5oKEfwZiakPXRd5C7OueEGBL50oh
21+
skip_symbols: false
22+
artifact: /.*\.nupkg/
23+
on:
24+
appveyor_repo_tag: true

build.ps1

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
# ----------------------------------------------
2+
# Build script
3+
# ----------------------------------------------
4+
5+
param
6+
(
7+
[switch] $Release,
8+
[switch] $Pack,
9+
[switch] $OnlyNetStandard,
10+
[switch] $ClearOnly
11+
)
12+
13+
$ErrorActionPreference = "Stop"
14+
15+
# ----------------------------------------------
16+
# Helper functions
17+
# ----------------------------------------------
18+
19+
function Test-IsWindows
20+
{
21+
[environment]::OSVersion.Platform -ne "Unix"
22+
}
23+
24+
function Invoke-Cmd ($cmd)
25+
{
26+
Write-Host $cmd -ForegroundColor DarkCyan
27+
if (Test-IsWindows) { $cmd = "cmd.exe /C $cmd" }
28+
Invoke-Expression -Command $cmd
29+
if ($LastExitCode -ne 0) { Write-Error "An error occured when executing '$cmd'."; return }
30+
}
31+
32+
function dotnet-info { Invoke-Cmd "dotnet --info" }
33+
function dotnet-version { Invoke-Cmd "dotnet --version" }
34+
function dotnet-build ($project, $argv) { Invoke-Cmd "dotnet build $project $argv" }
35+
function dotnet-run ($project, $argv) { Invoke-Cmd "dotnet run --project $project $argv" }
36+
function dotnet-test ($project, $argv) { Invoke-Cmd "dotnet test $project $argv" }
37+
function dotnet-pack ($project, $argv) { Invoke-Cmd "dotnet pack $project $argv" }
38+
39+
function Get-DotNetRuntimeVersion
40+
{
41+
$info = dotnet-info
42+
[System.Array]::Reverse($info)
43+
$version = $info | Where-Object { $_.Contains("Version") } | Select-Object -First 1
44+
$version.Split(":")[1].Trim()
45+
}
46+
47+
function dotnet-xunit ($project, $argv)
48+
{
49+
$fxversion = Get-DotNetRuntimeVersion
50+
Push-Location (Get-Item $project).Directory.FullName
51+
Invoke-Cmd "dotnet xunit -fxversion $fxversion $argv"
52+
Pop-Location
53+
}
54+
55+
function Write-DotnetVersion
56+
{
57+
$dotnetSdkVersion = dotnet-version
58+
Write-Host ".NET Core SDK version: $dotnetSdkVersion" -ForegroundColor Cyan
59+
}
60+
61+
function Write-DotnetInfo
62+
{
63+
$dotnetRuntimeVersion = Get-DotNetRuntimeVersion
64+
Write-Host ".NET Core Runtime version: $dotnetRuntimeVersion" -ForegroundColor Cyan
65+
}
66+
67+
function Test-Version ($project)
68+
{
69+
if ($env:APPVEYOR_REPO_TAG -eq $true)
70+
{
71+
Write-Host "Matching version against git tag..." -ForegroundColor Magenta
72+
73+
[xml] $xml = Get-Content $project
74+
[string] $version = $xml.Project.PropertyGroup.Version
75+
[string] $gitTag = $env:APPVEYOR_REPO_TAG_NAME
76+
77+
Write-Host "Project version: $version" -ForegroundColor Cyan
78+
Write-Host "Git tag version: $gitTag" -ForegroundColor Cyan
79+
80+
if (!$gitTag.EndsWith($version))
81+
{
82+
Write-Error "Version and Git tag do not match."
83+
}
84+
}
85+
}
86+
87+
function Update-AppVeyorBuildVersion ($project)
88+
{
89+
if ($env:APPVEYOR -eq $true)
90+
{
91+
Write-Host "Updating AppVeyor build version..." -ForegroundColor Magenta
92+
93+
[xml]$xml = Get-Content $project
94+
$version = $xml.Project.PropertyGroup.Version
95+
$buildVersion = "$version-$env:APPVEYOR_BUILD_NUMBER"
96+
Write-Host "Setting AppVeyor build version to $buildVersion."
97+
Update-AppveyorBuild -Version $buildVersion
98+
}
99+
}
100+
101+
function Remove-OldBuildArtifacts
102+
{
103+
Write-Host "Deleting old build artifacts..." -ForegroundColor Magenta
104+
105+
Get-ChildItem -Include "bin", "obj" -Recurse -Directory `
106+
| ForEach-Object {
107+
Write-Host "Removing folder $_" -ForegroundColor DarkGray
108+
Remove-Item $_ -Recurse -Force }
109+
}
110+
111+
function Get-TargetFrameworks ($projFile)
112+
{
113+
[xml]$proj = Get-Content $projFile
114+
($proj.Project.PropertyGroup.TargetFrameworks).Split(";")
115+
}
116+
117+
function Get-NetCoreTargetFramework ($projFile)
118+
{
119+
Get-TargetFrameworks $projFile | where { $_ -like "netstandard*" -or $_ -like "netcoreapp*" }
120+
}
121+
122+
function Get-FrameworkArg ($projFile)
123+
{
124+
if ($OnlyNetStandard.IsPresent) {
125+
$fw = Get-NetCoreTargetFramework $projFile
126+
"-f $fw"
127+
}
128+
else { "" }
129+
}
130+
131+
# ----------------------------------------------
132+
# Main
133+
# ----------------------------------------------
134+
135+
if ($ClearOnly.IsPresent) {
136+
Remove-OldBuildArtifacts
137+
return
138+
}
139+
140+
$src = ".\src\Giraffe.TokenRouter\Giraffe.TokenRouter.fsproj"
141+
$tests = ".\tests\Giraffe.TokenRouter.Tests\Giraffe.TokenRouter.Tests.fsproj"
142+
143+
Update-AppVeyorBuildVersion $src
144+
Test-Version $src
145+
Write-DotnetVersion
146+
Write-DotnetInfo
147+
Remove-OldBuildArtifacts
148+
149+
$configuration = if ($Release.IsPresent) { "Release" } else { "Debug" }
150+
151+
Write-Host "Building Giraffe.TokenRouter..." -ForegroundColor Magenta
152+
$framework = Get-FrameworkArg $src
153+
dotnet-build $src "-c $configuration $framework"
154+
155+
if (!$ExcludeTests.IsPresent -and !$Run.IsPresent)
156+
{
157+
Write-Host "Building and running tests..." -ForegroundColor Magenta
158+
$framework = Get-FrameworkArg $tests
159+
160+
dotnet-build $tests $framework
161+
162+
$xunitArgs = ""
163+
if(!(Test-IsWindows)) { $tfw = Get-NetCoreTargetFramework $tests; $xunitArgs = "-framework $tfw" }
164+
dotnet-xunit $tests $xunitArgs
165+
}
166+
167+
if ($Pack.IsPresent)
168+
{
169+
Write-Host "Packaging all NuGet packages..." -ForegroundColor Magenta
170+
dotnet-pack $src "-c $configuration"
171+
}

build.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export FrameworkPathOverride=$(dirname $(which mono))/../lib/mono/4.5/
2+
pwsh ./build.ps1

global.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"projects": [ "src", "tests" ],
3+
"sdk": {
4+
"version": "2.1.4"
5+
}
6+
}

0 commit comments

Comments
 (0)