@marmeon/http
v0.3.0
Published
HTTP for Marmeon apps: controllers, views and page props, redirects, signed URLs, encrypted cookies and the UI-free client core.
Maintainers
Readme
@marmeon/http
HTTP for Marmeon apps: controllers, pages and their props, redirects, signed URLs, cookies, the Content-Security-Policy and the UI-free client core every visit in the browser goes through.
Installation
Part of every new Marmeon app: pnpm create marmeon installs it.
Apps import the router's everyday names from here too: defineRoutes, defineRequest, HttpContext, ContextOf and more.
A controller and its page
import type { Authenticated } from '@marmeon/auth';
import type { Row } from '@marmeon/database';
import { Controller, type HttpContext } from '@marmeon/http';
export class ShowNoteController extends Controller {
handle(ctx: HttpContext<Authenticated, { note: Row<'notes'> }>) {
if (ctx.params.note.user_id !== ctx.user.id) return this.redirect().route('notes.index');
return this.view('notes/Show', { note: ctx.params.note });
}
}The page modules/notes/views/Show.tsx gets its props typed from the controller: PageProps<ShowNoteController>.
Documentation
- Controllers
- Responses
- Pages & Layouts
- URL Generation
- Content Security Policy
- Request Lifecycle
- Client Features & Tab Sync
- Error Handling: error codes
MIT · part of Marmeon
