@owlmeans/route
v0.1.7
Published
Route model factory and type definitions for OwlMeans modules.
Readme
@owlmeans/route
Route model factory and type definitions for OwlMeans modules.
Overview
route()creates aCommonRouteModelused as the first argument tomodule()frontend()/backend()/socket()helpers set the route'sAppTypeand parentRouteMethodenum covers HTTP verbs;RouteProtocolscovershttp/ws- This package is a dependency of
@owlmeans/module— you rarely use it directly unless defining module-level routes
Installation
bun add @owlmeans/routeUsage
Define routes for modules (typically via @owlmeans/server-app re-exports):
import { route, frontend, backend, socket, RouteMethod } from '@owlmeans/route'
import { module } from '@owlmeans/module'
// Backend REST route
const createRoute = module(
route('story-create', '/stories', backend('api', RouteMethod.POST))
)
// Frontend client route nested under parent
const storyRoute = module(
route('story-view', '/stories/:id', frontend('app'))
)
// WebSocket route
const wsRoute = module(
route('story-ws', '/stories/stream', socket('api'))
)API
route(alias, path, opts?): CommonRouteModel
Creates a route model. opts can be a RouteOptions object or the result of frontend(), backend(), or socket().
frontend(parent?, sticky?): Partial<RouteOptions>
Returns options marking the route as frontend (AppType.Frontend), optionally with a parent alias.
backend(parent?, method?): Partial<RouteOptions>
Returns options marking the route as backend (AppType.Backend), optionally with a parent alias and RouteMethod.
socket(parent?): Partial<RouteOptions>
Returns options for a WebSocket route with RouteProtocols.SOCKET.
RouteMethod
enum RouteMethod { GET, POST, PATCH, PUT, DELETE }RouteProtocols
enum RouteProtocols { WEB = 'http', SOCKET = 'ws' }Related Packages
@owlmeans/module—module()takes aCommonRouteModelas first argument@owlmeans/server-app— re-exportsrouteasbroute(backend) alongsideroute
