Bix.Bun 1.0.0-beta-001

This is a prerelease version of Bix.Bun.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package Bix.Bun --version 1.0.0-beta-001                
NuGet\Install-Package Bix.Bun -Version 1.0.0-beta-001                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Bix.Bun" Version="1.0.0-beta-001" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Bix.Bun --version 1.0.0-beta-001                
#r "nuget: Bix.Bun, 1.0.0-beta-001"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Bix.Bun as a Cake Addin
#addin nuget:?package=Bix.Bun&version=1.0.0-beta-001&prerelease

// Install Bix.Bun as a Cake Tool
#tool nuget:?package=Bix.Bun&version=1.0.0-beta-001&prerelease                

Bix

Bix which can be found in src/Bix is an F# microframework built on top of Bun.serve although the name is just a codename for now (until I decide it's good to go), this microframework is heavily inspired by Giraffe, and Saturn frameworks from F# land so if you have ever used that server model then Bix will feel fairly similar, I plan to add a saturn like router eventually

Bix.Bun

Bix.Bun exposes a bun.sh specific request handler, and other http handlers that may contain Bun specific APIs like Bun.file to read files

Check the sample at src/Bix.Bun.Sample/Program.fs

Bix.Deno

Bix.Deno exposes a deno specific request handler, and other http handlers that may contain Bun specific APIs like Deno.open to read files

Check the sample at src/Bix.Deno.Sample/Program.fs

// For more information see https://aka.ms/fsharp-console-apps
open Bix
open Bix.Types
open Bix.Handlers
open Bix.Router

open Bix.Deno

let checkCredentials: HttpHandler =
    fun next ctx ->
        let req: Request = ctx.Request
        let bearer = req.headers.get "Authorization" |> Option.ofObj
        // dummy handler
        match bearer with
        | None -> (setStatusCode (401) >=> sendText "Not Authorized") next ctx
        | Some token -> next ctx

let routes =
    Router.Empty
    |> Router.get ("/", fun next ctx -> sendText "Hello, World!" next ctx)
    |> Router.get ("/posts/:slug", fun next ctx ->
        promise { // promise based handlers are supported
            let slug = ctx.PathParams "slug"
            let! post = Database.find slug // database from somewhere
            let! html = Views.renderPost post // views from somewhere
            return! sendHtml html next ctx
        }
    )
    |> Router.get ("/json", fun next ctx ->
        let content = {| name = "Bix Server!"; Date = System.DateTime.Now |}
        sendJson content next ctx
    )
    |> Router.get ("/protected", (checkCredentials >=> (fun next ctx -> sendText "I'm protected!" next ctx)))


Server.Empty
|> Server.withRouter routes
|> Server.withDevelopment true
|> Server.withPort 5000
|> Server.run
|> Promise.start

Note: When Working with deno, you need to have the following fields in your import map

{
  "imports": {
    "urlpattern-polyfill": "https://cdn.skypack.dev/pin/urlpattern-polyfill@v5.0.3-5dMKTgPBkStj8a3hiMD2/mode=imports,min/optimized/urlpattern-polyfill.js",
    "http": "https://deno.land/std@0.147.0/http/server.ts"
  }
}

This is to ensure bare imports within Bix.Browser.Types and Bix.Deno work just fine.

Development

This project is developed with VSCode in Linux/Windows/WSL but either rider, and visual studio should work just fine.

Requirements

Try the sample

if you have bun installed along deno the simplest way to run the samples is

  • bun start
  • bun start:deno

both commands will restore the projects and run fable, bun/deno in watch mode

Bun

After installing .NET + Bun just run

bun start on your terminal and it should just work

Deno

After installing .NET + Bun just run

dotnet tool restore && \
dotnet fable watch src/Bix.Deno.Sample -s -o dist/Bix.Deno.Sample --run deno run -A ./dist/Bix.Deno.Sample/Program.js`
Product 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 was computed.  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 was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0-beta-006 81 5/22/2024
1.0.0-beta-004 119 7/10/2023
1.0.0-beta-003 125 7/22/2022
1.0.0-beta-002 120 7/18/2022
1.0.0-beta-001 149 7/17/2022