https://github.com/lkwr/dar
A TypeScript Decorator based API router for Deno.
https://github.com/lkwr/dar
deno denoland typescript typescript-decorators
Last synced: about 1 month ago
JSON representation
A TypeScript Decorator based API router for Deno.
- Host: GitHub
- URL: https://github.com/lkwr/dar
- Owner: lkwr
- License: mit
- Created: 2022-04-03T14:58:33.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2024-02-15T09:37:57.000Z (over 2 years ago)
- Last Synced: 2025-02-20T19:06:34.536Z (over 1 year ago)
- Topics: deno, denoland, typescript, typescript-decorators
- Language: TypeScript
- Homepage: https://deno.land/x/dar
- Size: 81.1 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# This project is unmaintained, take a look at the successor [SentiumJS](https://github.com/sentium-js/sentium)!
This project is currently experimental and may not work properly! If you find any bug, please write an issue.
DAR
A TypeScript Decorator based API router for Deno.
Key Features •
Introduction •
How To Use •
Example •
Credits •
License
## Key Features
- Typescript with [Decorators](https://www.typescriptlang.org/docs/handbook/decorators.html)
- Made for [Deno](https://deno.land)
- works with [Deno Deploy](https://deno.com/deploy)
- Lightweight
- Zero _third party_ dependencies (only [std](https://deno.land/std) & my own modules ([x/vade](https://deno.land/x/vade)))
- Highly customizable
- Controller nesting (using `@Include()`)
- Native [URLPattern](https://developer.mozilla.org/en-US/docs/Web/API/URL_Pattern_API) routing
## Introduction
DAR (formerly Pterosaur) stands for "**D**ecorator based **A**PI **R**outer" and is aimed to be used as a REST API Server, which primarily uses JSON data. It is built to support [Deno Deploy](https://deno.com/deploy).
## How To Use
DAR is available via Deno's Thrid Party Modules.
```ts
import { ... } from 'https://deno.land/x/dar/mod.ts';
```
Create a simple controller class.
```ts
@Controller()
class SomeClass {
// Methods here
}
```
Create a simple get method.
```ts
@Get()
someMethod() {
return { success: true }
}
```
Create the application
```ts
const app: Application = new Application({
controller: [SomeClass],
});
```
And register the handler. We use Deno's Standard Library
```ts
await serve((request: Request) => app.handle(request), { port: 8080 });
```
And all together
```ts
import { ... } from 'https://deno.land/x/dar/mod.ts';
@Controller()
class SomeClass {
@Get()
someMethod() {
return { success: true }
}
}
const app: Application = new Application({
controller: [SomeClass],
});
await serve((request: Request) => app.handle(request), { port: 8080 });
```
## Run the example
```bash
$ deno run --allow-net https://deno.land/x/dar/examples/basic.ts
```
## Known issues
- Include decorator not working in Deno Deploy. Need to use controller options to nest controllers!
## You may also like...
- [Alosaur](https://github.com/alosaur/alosaur) - Another decorator based router
## Credits
This software uses the following open source projects:
- [Deno Standard Modules](https://deno.land/std)
- [Dinosaur icons created by Darius Dan - Flaticon](https://www.flaticon.com/free-icons/dinosaur)
## License
MIT
---
> Homepage [luke.id](https://luke.id) ·
> GitHub [@lkwr](https://github.com/lkwr) ·
> Twitter [@wlkrlk](https://twitter.com/wlkrlk)