Hinoto – A web framework written in Gleam, made for multi JavaScript runtimes

1 month ago 8

Last commit Repository Stars Issues Open Issues Bug Issues

fire

A web framework written in Gleam, designed for multiple JavaScript runtimes!

  • 🌐 Support multi runtimes
    Supports JavaScript runtimes supported by Gleam (Node.js, Deno, Bun) and CloudFlare Workers.
  • 🧩 Module first
    Features are divided into modules, generating JavaScript that is advantageous for Tree-shaking. Additionally, no extra FFI code is mixed in during bundling.
  • 🔧 Custom context
    The Hinoto type can contain arbitrary context, allowing runtime-specific information to be handled in the same way.

You can easily set up a server running on CloudFlare Workers using hinoto/cli.

gleam deps download # Setup project for CloudFlare workers gleam run -m hinoto/cli -- workers init # Preview wrangler dev

Write code like the following in ./src/{project name}.gleam. Note that if you answered "yes" to the question Do you want to overwrite {project name}.gleam with a minimal server example? in hinoto/cli, a working server is already written.

import conversation.{Text} import gleam/http/response import gleam/javascript/promise import hinoto.{type DefaultContext, type Hinoto} pub fn main(hinoto: Hinoto(DefaultContext)) -> Hinoto(DefaultContext) { use _req <- hinoto.handle(hinoto) response.new(200) |> response.set_body(Text("<h1>Hello!</h1>")) |> response.set_header("content-type", "text/html") |> promise.resolve }

Add dependencies for hinoto and hinoto_cli to the dependencies section of gleam.toml.

hinoto = { git = "https://github.com/Comamoca/hinoto", ref = "main" } hinoto_cli = { git = "https://github.com/Comamoca/hinoto_cli", ref = "main" }
gleam run -m hinoto/cli -- workers init wrangler dev

For developing with various target JavaScript runtimes and CloudFlare Workers, wrangler is required.

cd example/ # For CF Workers cd workers wrangler dev # For node.js cd node_server # For deno cd deno_server # For bun cd bun_server
  • Support for WinterJS
  • Add middleware

MIT

Read Entire Article