Skip to content

NeaByteLab/Deserve

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

57 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Deserve

Build HTTP server effortlessly with zero configuration for productivity.

Deno JSR CI License

Features

  • Zero Config — No build step for the server. Point to a routes directory and serve.
  • File-Based Routing — Drop files in routes/; export GET, POST, etc. File structure is your API.
  • Context — Request wrapper: body (JSON/form/text), query, params, cookies, headers, ctx.send.
  • Middleware — Global, path-specific. CORS, SecHeaders, Body Limit, Basic Auth, Session, WebSocket.
  • Static Filesrouter.static(urlPath, options) with optional etag and cache-control.
  • Error Handling — Pluggable error response builder and error middleware; default HTML/JSON by Accept.
  • Worker Pool — Optional worker pool for CPU-bound work; enable via worker: { scriptURL, poolSize }.
  • Frontend Optional — Use any stack (Vite, React, etc.); Deserve stays the server.

Installation

Note

Prerequisites: Deno 2.5.4 or later.

# Add Deserve from JSR
deno add jsr:@neabyte/deserve

See the installation guide for details.

Quick Start

Create a routes directory and export HTTP method handlers. Start the server.

import { Router } from 'jsr:@neabyte/deserve'

// Create router and point to your routes directory
const router = new Router({ routesDir: './routes' })

// Optional: enable worker pool for CPU-bound work (ctx.state.worker.run(payload) in routes)
// const router = new Router({
//   routesDir: './routes',
//   worker: { scriptURL: import.meta.resolve('./worker.ts'), poolSize: 4 }
// })

// Start server on port 8000
await router.serve(8000)

Example routeroutes/hello.ts:

import type { Context } from 'jsr:@neabyte/deserve'

// Export GET (or POST, PUT, etc.) — path comes from file location
export function GET(ctx: Context) {
  return ctx.send.json({ message: 'Hello from Deserve' })
}

Build & Test

From the repo root (requires Deno).

Check — format, lint, and typecheck:

# Format, lint, and typecheck source
deno task check

Test — run tests (under tests/, uses --allow-read for fixtures):

# Run tests in tests/ (uses --allow-read for fixtures)
deno task test

Benchmark — performance runs with autocannon; see benchmark/README.md for how to run and interpret results.

Documentation

Full docs (EN / ID): docs-deserve.neabyte.com

  • Getting Started — Installation, Quick Start, Server & Routes configuration
  • Core Concepts — Philosophy, file-based routing, route patterns, Context, request handling
  • Middleware — Global, route-specific, Basic Auth, Body Limit, CORS, Security Headers, WebSocket
  • Response — JSON, text, HTML, file/data download, redirect, custom
  • Static Files — Basic and multiple directories
  • Error Handling — Default behavior, error object details

Contributing

  • Bugs & ideasGitHub Issues
  • Code & docsPull Requests welcome; docs support English and Indonesian.
  • Use it — Try Deserve in your projects and share feedback.

License

This project is licensed under the MIT license. See LICENSE for details.