Skip to main content
Deno 2 is finally here 🎉️
Learn more

peko-chick

Peko

  Routing     Request handling     Response caching     Events  

API DOCS

Philosophy

  • First-class frontend - Designed for server-side-rendering, use your library of choice!
  • Production-ready backend - Fully tested typescript server and utilities.
  • Software minimalism - Sleek runtime with no build step. Uses only the Deno std library.
  • Ease of adoption - Intuitive API, lots of examples and no fixed project structure.

Any feature suggestions or code reviews are very welcome!

Get started

A secure and scalable webapp in one file 🧑‍💻🌠

Try the examples:

  1. Deno is sick. Install it.

  2. $ git clone https://github.com/sebringrose/peko.git
  3. $ cd peko/examples
  4. $ deno task start:dev

Note: Lit-html VS Code plugin recommended if using HTM & Preact.

Import to your project:

import * as Peko from "https://deno.land/x/peko/mod.ts"

and if you don’t want unnecessary utitlies:

import { Server } from "https://deno.land/x/peko/server.ts"

Deployment

Instantly deploy from GitHub with Deno Deploy (deploy the auth or preact examples if you fancy it 💖).

Overview

Routing

Requests are matched to a mutable array of Routes. Routes can be added or removed at runtime via the addRoute and removeRoute server methods.

Request handling

The included staticHandler, ssrHandler and sseHandler handlers can be plugged straight into a route and reduce boilerplate code for serving static assets, rendering JavaScript apps to html or streaming server-sent events respectively. There are also authentication, logging and caching middleware. Of course, you can also create your own middleware or handlers and plug them into your routes (see examples/custom-handler).

Response caching

In stateless computing, memory should only be used for source code and disposable cache data. Response caching ensures that we only store data that can be regenerated or refetched. Peko provides a ResponseCache utility for this. The cacher middleware wraps it and provides drop in response caching for your routes. The ResponseCache is indexed by serializing the incoming RequestContext and has a configurable cache item lifetime. Coming soon: Automatically drop items when system memory is close to full.

Events

Realtime apps can be built with Events. Events are created by Emitters via the .emit method. Emitters can be subscribed to manually Emitter.subscribe or given to the sseHandler to stream Server-sent events to connected clients (see examples/sse).

The modern edge is cool because…

Our apps can share source code across frontend and backend. We can have all of the SEO and UX benefits of SSR without any JavaScript transpilation or bundling. We can write classes that let users store data in the browser until they decide to back it up to the cloud. If we want TS on the server we can emit JS versions of code to the browser. This completely eliminates part of the traditional JavaScript toolchain, increasing project maintainability and simplicity, all while making our software even faster.

Better yet, Peko is not build for any specific frontend framework or library. You can use barebones HTML, React, Preact, Vue… you name it (if you do set up a React or Vue project please consider adding it to the examples). Simply plug your app-rendering logic into the Render function of an SSRRoute.

This is all made possible by powerful new JavaScript tools. Deno is built to the ECMAScript specification. This makes it compatible with browser JavaScript which elimates the need to generate separate client and server JavaScript bundles (the support for URL imports is the secret sauce). UI libraries like Preact combined with htm offer lightning fast client-side hydration with a browser-friendly markup syntax. On top of this Deno has native TypeScript support, a rich runtime API and loads of community tools for your back-end needs.

This project started out of excitement for the elegancy of Deno and the freedom it would bring to the JavaScript community. At time of writing all library code has been written and maintained by me. If you are interested in contributing please submit a PR or get in contact :D