@y0x54a/bunda v0.1.0
Bunda
Bunda (Mother) - A lightweight web framework for the Bun javascript runtime.
Installing
bun add @y0x54a/bundaExample
import {Bunda} from "@y0x54a/bunda";
const app = await Bunda.serve();
app.router.get("/", ctx => ctx.text("Hi!"));Using StackRouter
import {Bunda, StackRouter} from "@y0x54a/bunda";
const app = await Bunda.serve({
services: {
router: Bunda.classService(StackRouter)
}
});
app.router.use(ctx => ctx.text("Hi!"));Using PathnameRouter
import {Bunda, PathnameRouter} from "@y0x54a/bunda";
const app = await Bunda.serve({
services: {
router: Bunda.classService(PathnameRouter)
}
});
app.router.use((ctx, next) => next(ctx));
app.router.get("/", ctx => ctx.text("Hi!"), [(ctx, next) => next(ctx)]);
app.router.get("/ping", ctx => ctx.text("Pong!"));Using FetchHandler
import {Bunda, FetchHandler} from "@y0x54a/bunda";
const app = await Bunda.serve({
services: {
fetchHandler: Bunda.rawService(new FetchHandler({status: 403, message: "Forbidden"}))
}
});
app.router.get("/ping", ctx => ctx.text("Pong!"));Using ErrorHandler
import {Bunda, ErrorHandler} from "@y0x54a/bunda";
const app = await Bunda.serve({
services: {
errorHandler: Bunda.rawService(new ErrorHandler({message: "Please see your server logs!"}))
}
});
app.router.get("/", () => Promise.reject(new Error()));API
Bunda
Props
routerfetchHandlererrorHandlerisServedisDevelopment
namesservicesMethods
constructor({services?})serve()stop()
has(name)get(name)getIf(name)raw(name, value)rawIf(name, value)class(name, value)classIf(name, value)factory(name, value)factoryIf(name, value)register(name, service)registers(services)registerIf(name, service)registersIf(services)unregister(name)unregisters(names)unregisterIf(name)unregistersIf(names)resolve(name, args?)resolveIf(name, args?, retval?)create(name, args?)createIf(name, args?, retval?)Static Methods
create({services?})serve({services?})
rawService(value)classService(value)factoryService(value)
Context
Props
containerrequeststateurlmethodheaderspathpathnamequeryqueryParamssearchsearchParamsMethods
constructor({container, request, state?})redirect(url, status?, headers?, options?)response(body, status?, headers?, options?)json(json, status?, headers?, options?)text(text, status?, headers?, options?)html(html, status?, headers?, options?)
Errinfo
Props
codeerrorcontext?Methods
constructor({code, error, context?})Static Props
FETCHERRORStatic Methods
fetch(error, context)error(error)
Url
Props
schemeprotocolusernamepasswordhosthostnameportpathpathnamequeryqueryParamssearchsearchParamshashfragmentoriginhrefMethods
constructor(url, base?)toString()toJSON()
Container
Props
namesservicesMethods
constructor(services?)has(name)get(name)getIf(name)raw(name, value)rawIf(name, value)class(name, value)classIf(name, value)factory(name, value)factoryIf(name, value)register(name, service)registers(services)registerIf(name, service)registersIf(services)unregister(name)unregisters(names)unregisterIf(name)unregistersIf(names)resolve(name, args?)resolveIf(name, args?, retval?)create(name, args?)createIf(name, args?, retval?)Static Methods
rawService(value)classService(value)factoryService(value)
Service
Props
valueexportsisResolvedMethods
constructor(value)resolve(args?)create(args?)
RawService
Props
valueexportsisResolvedMethods
constructor(value)resolve(args?)create(args?)
ClassService
Props
valueexportsisResolvedMethods
constructor(value)resolve(args?)create(args?)
FactoryService
Props
valueexportsisResolvedMethods
constructor(value)resolve(args?)create(args?)
FetchHandler
Props
statusmessageMethods
constructor({status?, message?})handle(context)
ErrorHandler
Props
statusmessagefallbackMethods
constructor({status?, message?, fallback?})handle(errinfo)
StackRouter
Props
lengthfactoriesMethods
constructor(factories?)use(factory)uses(factories)unuse(factory)unuses(factories)handle(context, next)
PathnameRouter
Props
pathroutesmiddlewareMethods
constructor({path?, routes?, middleware?})use(factory)uses(factories)unuse(factory)unuses(factories)get(path, factory, middleware?)head(path, factory, middleware?)post(path, factory, middleware?)put(path, factory, middleware?)delete(path, factory, middleware?)connect(path, factory, middleware?)options(path, factory, middleware?)trace(path, factory, middleware?)patch(path, factory, middleware?)register(route)registers(routes)unregister(route)unregisters(routes)handle(context, next)
PathnameRoute
Props
pathmethodfactorymiddlewareMethods
constructor({path, method, factory, middleware?})use(factory)uses(factories)unuse(factory)unuses(factories)handle(context)
3 years ago