Giter Site home page Giter Site logo

angelmunoz / bix Goto Github PK

View Code? Open in Web Editor NEW
31.0 5.0 1.0 94 KB

Bix, an F# micro-framework for cross-runtime JavaScript backends

License: MIT License

F# 100.00%
bun cloudflare cloudflare-workers deno fable fable-compiler framework fsharp javascript node

bix's Introduction

Bix

the "Bix" name is just a codename for now (until I decide it's good to go).

Templates

dotnet new --install Bix.Templates::*

  • dotnet new bix.bun -o BunProject
  • dotnet new bix.cloudflare -o CloudFlareWorker
  • dotnet new bix.deno -o DenoProject

An F# microframework that provides a router and http handler abstractions for web frameworks that work with a Request -> Response http server model.

Examples of runtimes that work with this model:

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.

An hypotetical example could be like the following code:

// define a function that takes HttpHandlers to satisfy existing handler constrains
let authenticateOrRedirect (authenticatedRoute: HttpHandler, notAuthenticatedRoute: HttpHandler) =
    Handlers.authenticateUser
        authenticatedRoute
        notAuthenticatedRoute

// compose different handlers for code reusability
// and granular control of handler execution
let checkAdminCredentials successRoute =
    authenticateOrRedirect (successRoute, Admin.Login)
    >=> Handlers.requiresAdmin

let checkUserCredentials successRoute =
    authenticateOrRedirect (successRoute, Views.Login)
    >=> Handlers.requiresUserOrAbove

// define routes for this application
let routes =
    // check the Cloud flare Worker sample/tempalte to see other router options
    // basic, giraffe, and saturn like
    Router.Empty
    |> Router.get("/", authenticateOrRedirect >=> Views.Landing)
    |> Router.get ("/login", authenticateOrRedirect >=> Views.Login)
    |> Router.get ("/me", checkUserCredentials(Views.Login))
    |> Router.get ("/portal", checkUserCredentials(Views.Portal))
    |> Router.get ("/admin", checkAdminCredentials(Admin.Portal))
    |> Router.post ("/users", checkAdminCredentials(Api.Users.Create >=> negotiateContent))
    |> Router.patch ("/users/:id", checkAdminCredentials(Api.Users.Update >=> negotiateContent))

// Start the web server
Server.Empty
|> Server.withPort 5000
|> Server.withDevelopment true
|> Server.withRouter routes
|> Server.run

The idea is to create simple and single purposed functions that work like middleware so you can organize and re-use

Adapters

Bix currently has two adapters

  • Bix.Deno
  • Bix.Bun

Adapters under investigation:

  • Bix.ServiceWorker
  • Bix.CloudflareWorker

Development

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

Requirements

Try the samples

Depending on what you want to try change the directory to your selected sample, example: cd samples/Bix.Bun.Sample and run one of the following commands

  1. dotnet tool restore (run once per clone)
  2. start the project
    • bun start
    • deno task start

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.