|
1 | | -# Deserve [](LICENSE) [](https://deno.land) [](https://jsr.io/@neabyte/deserve) |
| 1 | +<div align="center"> |
| 2 | + |
| 3 | +# Deserve |
2 | 4 |
|
3 | 5 | Build HTTP server effortlessly with zero configuration for productivity. |
4 | 6 |
|
5 | | -## Installation |
| 7 | +[](https://deno.com) [](https://jsr.io/@neabyte/deserve) [](https://github.com/NeaByteLab/Deserve/actions/workflows/ci.yaml) [](LICENSE) |
| 8 | + |
| 9 | +</div> |
| 10 | + |
| 11 | +## Features |
6 | 12 |
|
7 | | -Install [Deno](https://github.com/denoland/deno_install) 2.5.4+ and run `deno init` for new projects. |
| 13 | +- **Zero config** — No build step for the server. Point to a routes directory and serve. |
| 14 | +- **File-Based Routing** — Drop files in `routes/`; export `GET`, `POST`, etc. File structure is your API. |
| 15 | +- **Context** — Request wrapper: body (JSON/form/text), query, params, cookies, headers, `ctx.send`. |
| 16 | +- **Middleware** — Global, path-specific. CORS, SecHeaders, Body Limit, Basic Auth, Session, WebSocket. |
| 17 | +- **Static files** — `router.static(urlPath, options)` with optional etag and cache-control. |
| 18 | +- **Error handling** — Pluggable error response builder and error middleware; default HTML/JSON by `Accept`. |
| 19 | +- **Frontend optional** — Use any stack (Vite, React, etc.); Deserve stays the server. |
8 | 20 |
|
9 | | -Add Deserve using the `deno add` command: |
| 21 | +## Installation |
| 22 | + |
| 23 | +> [!NOTE] |
| 24 | +> **Prerequisites:** [Deno](https://deno.com/) 2.5.4 or later. |
10 | 25 |
|
11 | 26 | ```bash |
| 27 | +# Add Deserve from JSR |
12 | 28 | deno add jsr:@neabyte/deserve |
13 | 29 | ``` |
14 | 30 |
|
15 | | -Follow our [installing guide](https://docs-deserve.neabyte.com/en/getting-started/installation) for more information. |
16 | | - |
17 | | -## Table of Contents |
18 | | - |
19 | | -- **Getting Started** |
20 | | - - [Installation](https://docs-deserve.neabyte.com/en/getting-started/installation) - Set up Deserve in your project |
21 | | - - [Quick Start](https://docs-deserve.neabyte.com/en/getting-started/quick-start) - Create your first API in minutes |
22 | | - - [Server Configuration](https://docs-deserve.neabyte.com/en/getting-started/server-configuration) - Server setup and shutdown |
23 | | - - [Routes Configuration](https://docs-deserve.neabyte.com/en/getting-started/routes-configuration) - Configure router options |
24 | | - |
25 | | -- **Core Concepts** |
26 | | - - [Philosophy](https://docs-deserve.neabyte.com/en/core-concepts/philosophy) - Framework design principles |
27 | | - - [File-based Routing](https://docs-deserve.neabyte.com/en/core-concepts/file-based-routing) - How file structure becomes API endpoints |
28 | | - - [Route Patterns](https://docs-deserve.neabyte.com/en/core-concepts/route-patterns) - Dynamic routes and parameter matching |
29 | | - - [Context Object](https://docs-deserve.neabyte.com/en/core-concepts/context-object) - Request context wrapper with convenient methods |
30 | | - - [Request Handling](https://docs-deserve.neabyte.com/en/core-concepts/request-handling) - Enhanced request object with automatic parsing |
31 | | - |
32 | | -- **Middleware** |
33 | | - - [Use Global](https://docs-deserve.neabyte.com/en/middleware/global) - Cross-cutting functionality |
34 | | - - [Use Route-Specific](https://docs-deserve.neabyte.com/en/middleware/route-specific) - Targeted middleware for specific routes |
35 | | - - [Basic Auth](https://docs-deserve.neabyte.com/en/middleware/basic-auth) - HTTP Basic Authentication |
36 | | - - [Body Limit](https://docs-deserve.neabyte.com/en/middleware/body-limit) - Enforce maximum request body size |
37 | | - - [CORS](https://docs-deserve.neabyte.com/en/middleware/cors) - Cross-origin request handling |
38 | | - - [Security Headers](https://docs-deserve.neabyte.com/en/middleware/security-headers) - Set HTTP security headers to protect your application |
39 | | - - [WebSocket](https://docs-deserve.neabyte.com/en/middleware/websocket) - Real-time bidirectional communication |
40 | | - |
41 | | -- **Response Utilities** |
42 | | - - [JSON Format](https://docs-deserve.neabyte.com/en/response/json) - Create JSON responses easily |
43 | | - - [Text Format](https://docs-deserve.neabyte.com/en/response/text) - Plain text responses |
44 | | - - [HTML Format](https://docs-deserve.neabyte.com/en/response/html) - HTML content responses |
45 | | - - [File Downloads](https://docs-deserve.neabyte.com/en/response/file) - Download files from filesystem |
46 | | - - [Data Downloads](https://docs-deserve.neabyte.com/en/response/data) - Download in-memory content |
47 | | - - [Redirects](https://docs-deserve.neabyte.com/en/response/redirect) - Redirect responses |
48 | | - - [Custom Responses](https://docs-deserve.neabyte.com/en/response/custom) - Full control over response options |
49 | | - |
50 | | -- **Static Files** |
51 | | - - [Basic Static Serving](https://docs-deserve.neabyte.com/en/static-file/basic) - Serve static files from directories |
52 | | - - [Multiple Directories](https://docs-deserve.neabyte.com/en/static-file/multiple) - Serve from multiple locations |
53 | | - |
54 | | -- **Error Handling** |
55 | | - - [Default Behavior](https://docs-deserve.neabyte.com/en/error-handling/default-behavior) - Automatic error handling |
56 | | - - [Object Details](https://docs-deserve.neabyte.com/en/error-handling/object-details) - Detailed error information |
| 31 | +See the [installation guide](https://docs-deserve.neabyte.com/en/getting-started/installation) for details. |
57 | 32 |
|
58 | | -## Contributing |
| 33 | +## Quick Start |
| 34 | + |
| 35 | +Create a routes directory and export HTTP method handlers. Start the server. |
| 36 | + |
| 37 | +```typescript |
| 38 | +import { Router } from 'jsr:@neabyte/deserve' |
| 39 | + |
| 40 | +// Create router and point to your routes directory |
| 41 | +const router = new Router({ routesDir: './routes' }) |
| 42 | + |
| 43 | +// Start server on port 8000 |
| 44 | +await router.serve(8000) |
| 45 | +``` |
| 46 | + |
| 47 | +**Example route** — `routes/hello.ts`: |
| 48 | + |
| 49 | +```typescript |
| 50 | +import type { Context } from 'jsr:@neabyte/deserve' |
| 51 | + |
| 52 | +// Export GET (or POST, PUT, etc.) — path comes from file location |
| 53 | +export function GET(ctx: Context) { |
| 54 | + return ctx.send.json({ message: 'Hello from Deserve' }) |
| 55 | +} |
| 56 | +``` |
59 | 57 |
|
60 | | -**Help us make Deserve even simpler!** Every contribution helps make building APIs effortless. |
| 58 | +- [Quick Start (docs)](https://docs-deserve.neabyte.com/en/getting-started/quick-start) |
| 59 | +- [File-Based Routing](https://docs-deserve.neabyte.com/en/core-concepts/file-based-routing) |
61 | 60 |
|
62 | | -### How to Contribute |
| 61 | +## Build & Test |
| 62 | + |
| 63 | +From the repo root (requires [Deno](https://deno.com/)). |
| 64 | + |
| 65 | +**Check** — format, lint, and typecheck: |
| 66 | + |
| 67 | +```bash |
| 68 | +# Format, lint, and typecheck source |
| 69 | +deno task check |
| 70 | +``` |
| 71 | + |
| 72 | +**Test** — run tests (under `tests/`, uses `--allow-read` for fixtures): |
| 73 | + |
| 74 | +```bash |
| 75 | +# Run tests in tests/ (uses --allow-read for fixtures) |
| 76 | +deno task test |
| 77 | +``` |
| 78 | + |
| 79 | +**Benchmark** — performance runs with autocannon; see [benchmark/README.md](benchmark/README.md) for how to run and interpret results. |
| 80 | + |
| 81 | +## Documentation |
| 82 | + |
| 83 | +Full docs (EN / ID): **[docs-deserve.neabyte.com](https://docs-deserve.neabyte.com)** |
| 84 | + |
| 85 | +- **Getting Started** — Installation, Quick Start, Server & Routes configuration |
| 86 | +- **Core Concepts** — Philosophy, file-based routing, route patterns, Context, request handling |
| 87 | +- **Middleware** — Global, route-specific, Basic Auth, Body Limit, CORS, Security Headers, WebSocket |
| 88 | +- **Response** — JSON, text, HTML, file/data download, redirect, custom |
| 89 | +- **Static Files** — Basic and multiple directories |
| 90 | +- **Error Handling** — Default behavior, error object details |
| 91 | + |
| 92 | +## Contributing |
63 | 93 |
|
64 | | -- **Report Bugs** - Found something broken? Let us know via [GitHub Issues](https://github.com/NeaByteLab/Deserve/issues) |
65 | | -- **Suggest Features** - Have an idea that aligns with our simplicity-first philosophy? [Create an issue](https://github.com/NeaByteLab/Deserve/issues/new) |
66 | | -- **Fix & Improve** - Submit [Pull Requests](https://github.com/NeaByteLab/Deserve/pulls) for bug fixes, typos, or code improvements |
67 | | -- **Build Middleware** - Create and share third-party middleware that extends Deserve's capabilities |
68 | | -- **Improve Docs** - Help us make the documentation clearer (supports English and Indonesian!) |
69 | | -- **Use Deserve** - The best contribution? Use it in your projects and share your feedback |
| 94 | +- **Bugs & ideas** — [GitHub Issues](https://github.com/NeaByteLab/Deserve/issues) |
| 95 | +- **Code & docs** — [Pull Requests](https://github.com/NeaByteLab/Deserve/pulls) welcome; docs support English and Indonesian. |
| 96 | +- **Use it** — Try Deserve in your projects and share feedback. |
70 | 97 |
|
71 | 98 | ## License |
72 | 99 |
|
73 | | -This project is licensed under the MIT license. See the [LICENSE](LICENSE) file for more info. |
| 100 | +This project is licensed under the MIT license. See [LICENSE](LICENSE) for details. |
0 commit comments