@bunarcane/arcane v0.1.0
Arcane
A minimal Bun web toolkit, designed with a focus on modern application development, offering built-in features to quickly making a web application.
Warning - This project is still highly unstable. If you are using this, please do not put it into production. Well, obviously.
Design Principles:
- Security by Default - Providing best practice for securing an application.
- Promote Modularity and Reusability - Structuring and organizing the application to be scalable.
- Ease of Use - Less complexity, fairly comprehensible.
- Performant - High performance and optimization.
- Out-of-the-Box - Providing extra features out-of-the-box.
- Customizable - No constraints, flexibility is key.
Table of Content
- Installation
- Quick Start
- Routing
- Reusable Modules
- Update later...
Installation
bun install @bunarcane/arcane
Quick Start
To get started with Arcane, you simply import the Arcane
class from package and
Routing
Routing in Arcane is very straightforward, just simply import the method createRouter()
and use the chain HTTP methods provided from it.
import { Arcane, createRouter, ok } from '@bunarcane/arcane'
const HelloWorld = createRouter()
.get('/', () => ok('Hello World'))
.compose()
new Arcane()
.use(HelloWorld)
.serve({
port: 7000,
context: 'Application starting on localhost:7000'
})
Reusable Modules
Arcane provided two types of method in order to make reusable modules:
createBridge
- Used for creating controller, that can communicate with theRequest
context.createModule
- As the name says, this method is used to create regular method.
In terms of implementation, these two are similar; the only difference is that createBridge
contains a method that includes the Request
context, which is used for handling request body, etc., while createModule
does not contain that method but can have flexible parameters similar to regular functions.
Creating a controller
import {
Arcane,
createRouter,
createBridge,
response,
ok
} from '@bunarcane/arcane'
const FooBarController = createBridge()
.impl('foo', () => ok('Hello! This is foo!'))
.impl('bar', () => response('Hi! This is bar!'))
.compose()
// Injecting to router
const FooBarRouter = createRouter()
.get('/foo', FooBarController.foo)
.get('/bar', FooBarController.bar)
.compose()
new Arcane()
.use(FooBarController)
.serve({
port: 7000,
context: 'Application starting on localhost:7000'
})
Creating a module
// middlewares.ts
import { createModule, useQuery } from '@bunarcane/arcane'
export type TFoo = {
bar: string
}
export type TBar= {
foo: string
}
export const FooBarMiddlewares = createModule()
.mod('validateFoo', (body: TFoo) => {
if (!body.bar) throw new Error('Bar is required!')
})
.mod('validateBar', () => {
const { foo } = useQuery<TBar>()
if (!foo) throw new Error('Foo is required!')
})
.compose()
// controller.ts
import { createBridge } from '@bunarcane/arcane'
import { TFoo, TBar, FooBarMiddlewares } from './middleware'
const FooBarController = createBridge()
.impl('foo', async (req) => {
const body = await req.json<TFoo>()
FooBarMiddlewares.validateFoo(body)
return response(body)
})
.impl('bar', () => {
FooBarMiddlewares.validateBar()
return ok('Hello! This is bar!')
})
.compose()
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago