Giraffe 7.0.2
dotnet add package Giraffe --version 7.0.2
NuGet\Install-Package Giraffe -Version 7.0.2
<PackageReference Include="Giraffe" Version="7.0.2" />
paket add Giraffe --version 7.0.2
#r "nuget: Giraffe, 7.0.2"
// Install Giraffe as a Cake Addin #addin nuget:?package=Giraffe&version=7.0.2 // Install Giraffe as a Cake Tool #tool nuget:?package=Giraffe&version=7.0.2
Giraffe
A functional ASP.NET Core micro web framework for building rich web applications.
Read this blog post on functional ASP.NET Core for more information.
Table of contents
- About
- Getting Started
- Documentation
- Sample applications
- Benchmarks
- Building and developing
- Contributing
- Nightly builds and NuGet feed
- Blog posts
- Videos
- License
- Contact and Slack Channel
- Support
About
Giraffe is an F# micro web framework for building rich web applications. It has been heavily inspired and is similar to Suave, but has been specifically designed with ASP.NET Core in mind and can be plugged into the ASP.NET Core pipeline via middleware. Giraffe applications are composed of so called HttpHandler
functions which can be thought of a mixture of Suave's WebParts and ASP.NET Core's middleware.
If you'd like to learn more about the motivation of this project please read my blog post on functional ASP.NET Core (some code samples in this blog post might be outdated today).
[!TIP] Check the release notes document to know how the system is evolving, and to get more information about breaking changes.
Who is it for?
Giraffe is intended for developers who want to build rich web applications on top of ASP.NET Core in a functional first approach. ASP.NET Core is a powerful web platform which has support by Microsoft and a huge developer community behind it and Giraffe is aimed at F# developers who want to benefit from that eco system.
It is not designed to be a competing web product which can be run standalone like NancyFx or Suave, but rather a lean micro framework which aims to complement ASP.NET Core where it comes short for functional developers. The fundamental idea is to build on top of the strong foundation of ASP.NET Core and re-use existing ASP.NET Core building blocks so F# developers can benefit from both worlds.
You can think of Giraffe as the functional counter part of the ASP.NET Core MVC framework.
Getting Started
Using dotnet-new
The easiest way to get started with Giraffe is by installing the giraffe-template
package, which adds a new template to your dotnet new
command line tool:
dotnet new install "giraffe-template::*"
Afterwards you can create a new Giraffe application by running dotnet new giraffe
.
If you are using dotnet core 2.1.4, you will need to specify the language: dotnet new giraffe -lang F#
For more information about the Giraffe template please visit the official giraffe-template repository.
Doing it manually
Install the Giraffe NuGet package*:
PM> Install-Package Giraffe
*) If you haven't installed the ASP.NET Core NuGet package yet then you'll also need to add a package reference to Microsoft.AspNetCore.App
:
PM> Install-Package Microsoft.AspNetCore.App
Alternatively you can also use the .NET CLI to add the packages:
dotnet add package Microsoft.AspNetCore.App
dotnet add package Giraffe
Next create a web application and plug it into the ASP.NET Core middleware:
open System
open Microsoft.AspNetCore.Builder
open Microsoft.AspNetCore.Hosting
open Microsoft.Extensions.Hosting
open Microsoft.Extensions.Logging
open Microsoft.Extensions.DependencyInjection
open Giraffe
let webApp =
choose [
route "/ping" >=> text "pong"
route "/" >=> htmlFile "/pages/index.html" ]
type Startup() =
member __.ConfigureServices (services : IServiceCollection) =
// Register default Giraffe dependencies
services.AddGiraffe() |> ignore
member __.Configure (app : IApplicationBuilder)
(env : IHostEnvironment)
(loggerFactory : ILoggerFactory) =
// Add Giraffe to the ASP.NET Core pipeline
app.UseGiraffe webApp
[<EntryPoint>]
let main _ =
Host.CreateDefaultBuilder()
.ConfigureWebHostDefaults(
fun webHostBuilder ->
webHostBuilder
.UseStartup<Startup>()
|> ignore)
.Build()
.Run()
0
Instead of creating a Startup
class you can also add Giraffe in a more functional way:
open System
open Microsoft.AspNetCore.Builder
open Microsoft.AspNetCore.Hosting
open Microsoft.Extensions.Hosting
open Microsoft.Extensions.DependencyInjection
open Giraffe
let webApp =
choose [
route "/ping" >=> text "pong"
route "/" >=> htmlFile "/pages/index.html" ]
let configureApp (app : IApplicationBuilder) =
// Add Giraffe to the ASP.NET Core pipeline
app.UseGiraffe webApp
let configureServices (services : IServiceCollection) =
// Add Giraffe dependencies
services.AddGiraffe() |> ignore
[<EntryPoint>]
let main _ =
Host.CreateDefaultBuilder()
.ConfigureWebHostDefaults(
fun webHostBuilder ->
webHostBuilder
.Configure(configureApp)
.ConfigureServices(configureServices)
|> ignore)
.Build()
.Run()
0
For more information please check the official Giraffe documentation.
Sample applications
Demo apps
There is a few sample applications which can be found in the samples
GitHub repository. Please check the README.md
there for further information.
Live apps
dusted.codes
My personal blog https://dusted.codes is also built with Giraffe and ASP.NET Core and all of the source code is published on GitHub for further reference.
More sample applications will be added in the future.
Benchmarks
Giraffe is part of the TechEmpower Web Framework Benchmarks and will be listed in the official results page in the upcoming Round 17 for the first time.
Unofficial test results are currently available on the TFB Status page.
As of today Giraffe competes in the Plaintext, JSON and Fortunes categories and has been doing pretty well so far, even outperforming ASP.NET Core MVC in Plaintext and JSON at the time of writing.
The latest implementation which is being used for the benchmark tests can be seen inside the TechEmpower repository.
Giraffe is also featured in Jimmy Byrd's dotnet-web-benchmarks where we've run earlier performance tests.
Building and developing
Giraffe is built with the latest .NET Core SDK, which works on Windows, macOS and Linux out of the box.
You can either install Microsoft Visual Studio or JetBrains Rider which both come with the latest .NET Core SDK or manually download and install the .NET Core SDK and use the .NET CLI or Visual Studio Code with the Ionide extension to build and develop Giraffe.
The easiest way to build Giraffe is via the .NET CLI.
Run dotnet build
from the root folder of the project to restore and build all projects in the solution:
dotnet build
Running dotnet test
from the root of the project will execute all test projects referenced in the solution:
dotnet test
Contributing
Help and feedback is always welcome and pull requests get accepted.
TL;DR
- First open an issue to discuss your changes
- After your change has been formally approved please submit your PR against the master branch
- Please follow the code convention by examining existing code
- Add/modify the
README.md
as required - Add/modify unit tests as required
- Please document your changes in the upcoming release notes in
RELEASE_NOTES.md
- PRs can only be approved and merged when all checks succeed (builds on Windows and Linux)
Discuss your change first
When contributing to this repository, please first discuss the change you wish to make via an open issue before submitting a pull request. For new feature requests please describe your idea in more detail and how it could benefit other users as well.
Please be aware that Giraffe strictly aims to remain as light as possible while providing generic functionality for building functional web applications. New feature work must be applicable to a broader user base and if this requirement cannot be sufficiently met then a pull request might get rejected. In the case of doubt the maintainer might rather reject a potentially useful feature than adding one too many. This measure is to protect the repository from feature bloat and shall not be taken personally.
Code conventions
We use Fantomas to ensure consistent code formatting across the project. Before committing, format your code by running the following command:
dotnet fantomas src samples tests
Keep documentation and unit tests up to date
If you intend to add or change an existing HttpHandler
then please update the README.md
file to reflect these changes there as well. If applicable unit tests must be added or updated and the project must successfully build before a pull request can be accepted.
Submit a pull request against master
The master
branch is the main and only branch which should be used for all pull requests. A merge into master
means that your changes are scheduled to go live with the very next release, which could happen any time from the same day up to a couple weeks (depending on priorities and urgency).
Only pull requests which pass all build checks and comply with the general coding guidelines can be approved.
If you have any further questions please let me know.
You can file an issue on GitHub, start a discussion on GitHub, or contact me via https://dusted.codes/about.
NuGet feed
All official release packages are published to the official and public NuGet feed.
Builds triggered by pull requests produce a NuGet package which can be downloaded as an artifact from the individual GitHub action.
Blog posts
Blog posts by author
- Functional ASP.NET Core
- Functional ASP.NET Core part 2 - Hello world from Giraffe
- Evolving my open source project from a one man repository to an OSS organisation
- Extending the Giraffe template with different view engine options
- Announcing Giraffe 1.0.0
- Giraffe 1.1.0 - More routing handlers, better model binding and brand new model validation API
Community blog posts
- Carry On! … Continuation over binding pipelines for functional web (by Gerard)
- A Functional Web with ASP.NET Core and F#'s Giraffe (by Scott Hanselman)
- Build a web service with F# and .NET Core 2.0 (by Phillip Carter)
- Giraffe brings F# functional programming to ASP.Net Core (by Paul Krill from InfoWorld)
- JSON Web Token with Giraffe and F# (by David Sinclair)
- WebSockets with Giraffe and F# (by David Sinclair)
- Use appsettings in a Giraffe web app (by Jan Tourlamain)
- Integrate Azure AD in your Giraffe web app (by Jan Tourlamain)
- Web development in F#: Getting started (by Samuele Resca)
- Build web service using F# and ASP.NET Core (by Samuele Resca)
If you have blogged about Giraffe, demonstrating a useful topic or some other tips or tricks then please feel free to submit a pull request and add your article to this list as a reference for other Giraffe users. Thank you!
Videos
- Getting Started with ASP.NET Core Giraffe (by Ody Mbegbu)
- Nikeza - Building the Backend with F# (by Let's Code .NET)
- Build a Simple Web API with F# + Giraffe (by HAMY LABS)
- Pipeline-oriented programming - Scott Wlaschin - NDC Porto 2023 (by Scott Wlaschin)
License
Current maintainers
Contact
If you have any further questions feel free to reach out to me via any of the mentioned social media on https://dusted.codes/about
Support
If you've got value from any of the content which I have created, but pull requests are not your thing, then I would also very much appreciate your support by buying me a coffee. Thank you!
<a href="https://www.buymeacoffee.com/dustinmoris" target="_blank"><img src="https://gist.githubusercontent.com/dustinmoris/8159363be2297ea76333a8b1823fd23c/raw/d93977425ccef3c5de9aeb2852b6d8e93ed50e55/bmac.svg" alt="Buy Me A Coffee"></a>
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net6.0
- FSharp.Core (>= 6.0.0)
- FSharp.SystemTextJson (>= 1.3.13)
- Giraffe.ViewEngine (>= 1.4.0)
- Microsoft.IO.RecyclableMemoryStream (>= 3.0.1)
- System.Text.Json (>= 8.0.5)
-
net7.0
- FSharp.Core (>= 6.0.0)
- FSharp.SystemTextJson (>= 1.3.13)
- Giraffe.ViewEngine (>= 1.4.0)
- Microsoft.IO.RecyclableMemoryStream (>= 3.0.1)
- System.Text.Json (>= 8.0.5)
-
net8.0
- FSharp.Core (>= 6.0.0)
- FSharp.SystemTextJson (>= 1.3.13)
- Giraffe.ViewEngine (>= 1.4.0)
- Microsoft.IO.RecyclableMemoryStream (>= 3.0.1)
- System.Text.Json (>= 8.0.5)
NuGet packages (45)
Showing the top 5 NuGet packages that depend on Giraffe:
Package | Downloads |
---|---|
Saturn
Opinionated, web development framework for F# which implements the server-side, functional MVC pattern |
|
Fable.Remoting.Giraffe
Giraffe-Fable adapter that generates routes for shared server spec with a Fable client. Client must use Fable.Remoting.Client |
|
Thoth.Json.Giraffe
JSON serializer for Giraffe implemented with Thoth.Json.Net |
|
Giraffe.SerilogExtensions
Giraffe plugin to use Serilog as the logger for your application |
|
Giraffe.Razor
Razor view engine support for the Giraffe web framework. |
GitHub repositories (2)
Showing the top 2 popular GitHub repositories that depend on Giraffe:
Repository | Stars |
---|---|
aws/aws-lambda-dotnet
Libraries, samples and tools to help .NET Core developers develop AWS Lambda functions.
|
|
osstotalsoft/nbb
.Net Building Blocks
|
Version | Downloads | Last updated |
---|---|---|
7.0.2 | 17,426 | 10/16/2024 |
7.0.2-alpha-002 | 108 | 9/20/2024 |
7.0.2-alpha-001 | 103 | 9/6/2024 |
7.0.1 | 12,357 | 8/27/2024 |
7.0.0 | 13,715 | 7/15/2024 |
7.0.0-alpha-001 | 910 | 7/8/2024 |
6.4.1-alpha-3 | 186 | 5/14/2024 |
6.4.1-alpha-2 | 89 | 5/13/2024 |
6.4.0 | 93,169 | 4/12/2024 |
6.4.0-alpha-1 | 517 | 3/15/2024 |
6.3.0 | 36,956 | 3/1/2024 |
6.3.0-alpha-1 | 111 | 2/26/2024 |
6.2.0 | 183,709 | 7/7/2023 |
6.2.0-beta001 | 130 | 7/7/2023 |
6.1.0 | 475 | 7/6/2023 |
6.1.0-beta002 | 136 | 7/6/2023 |
6.1.0-beta001 | 162 | 7/6/2023 |
6.0.0 | 645,243 | 4/9/2022 |
6.0.0-alpha-2 | 12,093 | 11/14/2021 |
6.0.0-alpha-1 | 19,674 | 11/10/2021 |
5.0.0 | 294,064 | 5/24/2021 |
5.0.0-rc-6 | 40,300 | 12/8/2020 |
5.0.0-rc-5 | 335 | 12/8/2020 |
5.0.0-rc-4 | 411 | 12/7/2020 |
5.0.0-rc-3 | 522 | 12/1/2020 |
5.0.0-rc-2 | 594 | 11/26/2020 |
5.0.0-rc-1 | 1,632 | 11/22/2020 |
5.0.0-alpha-003 | 1,926 | 9/1/2020 |
5.0.0-alpha-002 | 3,558 | 6/21/2020 |
5.0.0-alpha-001 | 1,142 | 5/27/2020 |
4.1.0 | 308,326 | 4/13/2020 |
4.0.1 | 198,008 | 10/18/2019 |
4.0.0 | 16,757 | 9/29/2019 |
3.6.0 | 152,883 | 2/10/2019 |
3.5.1 | 6,430 | 1/20/2019 |
3.5.0 | 7,326 | 12/28/2018 |
3.4.0 | 40,877 | 10/28/2018 |
3.3.0 | 1,135 | 10/28/2018 |
3.2.0 | 3,699 | 10/10/2018 |
3.1.0 | 31,988 | 9/28/2018 |
3.0.0 | 2,932 | 9/18/2018 |
2.0.1 | 4,473 | 8/20/2018 |
2.0.0 | 2,593 | 8/18/2018 |
1.2.0-preview-1 | 1,395 | 3/6/2018 |
1.1.0 | 99,705 | 2/16/2018 |
1.0.0 | 10,573 | 2/8/2018 |
0.1.0-beta-700 | 7,981 | 12/22/2017 |
0.1.0-beta-600 | 1,859 | 12/20/2017 |
0.1.0-beta-511 | 1,176 | 12/19/2017 |
0.1.0-beta-510 | 1,026 | 12/19/2017 |
0.1.0-beta-500 | 1,524 | 12/12/2017 |
0.1.0-beta-400 | 1,545 | 12/4/2017 |
0.1.0-beta-310 | 1,027 | 11/30/2017 |
0.1.0-beta-300 | 2,208 | 11/18/2017 |
0.1.0-beta-200 | 1,325 | 10/29/2017 |
0.1.0-beta-110 | 1,113 | 10/25/2017 |
0.1.0-beta-102 | 1,399 | 10/19/2017 |
0.1.0-beta-101 | 1,221 | 10/10/2017 |
0.1.0-beta-100 | 62,138 | 8/28/2017 |
0.1.0-beta-003 | 1,130 | 8/26/2017 |
0.1.0-beta-002 | 1,344 | 8/19/2017 |
0.1.0-beta-001 | 1,319 | 8/12/2017 |
0.1.0-alpha025 | 1,525 | 7/22/2017 |
0.1.0-alpha024 | 999 | 7/16/2017 |
0.1.0-alpha023 | 1,191 | 7/5/2017 |
0.1.0-alpha022 | 987 | 7/1/2017 |
0.1.0-alpha021 | 1,044 | 7/1/2017 |
0.1.0-alpha020 | 1,007 | 6/23/2017 |
0.1.0-alpha019 | 1,872 | 5/31/2017 |
0.1.0-alpha018 | 1,121 | 5/17/2017 |
0.1.0-alpha017 | 974 | 5/14/2017 |
0.1.0-alpha016 | 994 | 5/4/2017 |
0.1.0-alpha015 | 1,060 | 4/26/2017 |
0.1.0-alpha014 | 955 | 4/26/2017 |
0.1.0-alpha013 | 1,005 | 4/16/2017 |
0.1.0-alpha012 | 985 | 4/15/2017 |
0.1.0-alpha011 | 972 | 4/15/2017 |
0.1.0-alpha010 | 985 | 4/13/2017 |
0.1.0-alpha009 | 939 | 4/11/2017 |
0.1.0-alpha008 | 1,028 | 4/1/2017 |
0.1.0-alpha007 | 987 | 3/31/2017 |
0.1.0-alpha006 | 967 | 3/3/2017 |