Giter Site home page Giter Site logo

hono-fbr's Introduction

Hono FBR

Hono FBR is a lightweight, yet powerful addition to the Hono framework, designed to streamline the creation and management of routes through an intuitive file-based system. This library simplifies the process of defining routes, offering developers a more organized and scalable approach to handling web application endpoints, ultimately making the development process quicker, cleaner, and more intuitive. And with Hono's routing, this is all done blazingly fast!

Motivation

The idea behind Hono FBR is simple: make routing less of a headache in your SSR Hono app. As projects grow, managing routes traditionally becomes messy and confusing. This library introduces an entirely configurable, organized, file-based approach to tackle this issue head-on. This way, developers can quickly find and manage routes, making the development process smoother and more enjoyable. Hono FBR takes a great part of many modern frontend frameworks, and brings its simplicity to the backend, so you can focus on building great software.

What is file based routing?

File-based routing is all about organizing your web app's routes using a straightforward, folder-and-file system. In file-based routing, each part of your app's URL corresponds to a specific file or folder in your project. Instead of writing complex routing rules, you just create a new file or folder, and voila — your app knows where to go when someone visits that path. It's intuitive, clean, and means less time coding routing logic and more time making your app awesome.

Getting Started

Hono FBR is specifically built for use with Deno. As such, you can use the library by simply importing the library from https://raw.githubusercontent.com/iSchoen/Hono-FBR/master/mod.ts.

Usage

import { Hono } from "https://deno.land/x/hono/mod.ts";
import { getRoutes } from "https://github.com/iSchoen/Hono-FBR";

const app = new Hono();

app.route(
    "",
    await getRoutes({
        path: Deno.cwd() + "/routes",   // must be an absolute path
    })
)

Deno.serve({ port: 3000 }, app.fetch);

Route Creation

The following folder structure

routes
├── page.tsx
├── users
│   ├── page.tsx
│   └── :id
│       └── page.tsx
├── products
│   ├── page.tsx
│   └── :id
│       └── page.tsx
├── contact
│   └── page.tsx
└── about
    └── page.tsx

And the following configuration

getRoutes({
    path: Deno.cwd() + "/routes",
})

Will produce the following routes

"/",
"/contact",
"/about",
"/users",
"/users/:id",
"/products",
"/products/:id"

Note that while the examples above use .tsx files, the file based routing is not exclusive to jsx!

Dynamic Routes

In Hono, the part of the request URL prefixed with : is dynamic. This means that the route is passed in a parameter value that is dependent on the actual URL that matched to the dynamic route.

For example, a request to /products/10 would match to the /products/:id route and the route function would be provided Hono's context object where the value at context.req.param("id") would be 10.

API Reference

getRoutes

Generates all routes for Hono to match to. Returns a promise.

const app = new Hono();

app.route(
  "",
  await getRoutes({
    path: Deno.cwd() + "/routes",
  }),
);

RoutingConfig

You can configure how your routes are generated.

{
    path: string,
}

hono-fbr's People

Contributors

ischoen avatar

Watchers

 avatar

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.