Skip to main content

Danet - A savory web framework for Deno heavily inspired by Nest

Run tests codecov

  • Modules - exactly what you think they are.
  • Controllers - To handle requests.
  • Dependency Injection - Let Danet take care of instantiating stuff for you when it is the most convenient.
  • AuthGuards - Handle your Authentication/Authorization. The whole App get guard, Controllers get guard, Methods get guard, and you get a Guard…
  • Decorators - Modules, Controllers, Method, Body, Query Params, do more with less code !

Community

Join our discord

Docs

Documentation is available at https://savory.github.io/Danet/

It is obviously still a WIP.

Contributing

If you want to contribute, feel free ! Guidelines will be available here

How to use

If you are familiar with Nest (and if you’re not, go check it out), you will not be lost.

In this simplified example, we are building a todo-app:

Modules

@Module({
    controllers: [TodoController],
    injectables: [TodoService],
})
class TodoModule {}

Controllers

@Controller('todo')
class TodoController {
    //todoService will be automatically injected at runtime with DI
    constructor(private todoService: TodoService) {
    }

    @Get('')
    getTodos() {
        return this.todoService.getTodos();
    }

    @Get(':id')
    getOneTodo(@Param('id') todoId: string) {
        return this.todoService.getOne(todoId);
    }

    @Post('')
    createTodo(@Body() todo) {
        return this.todoService.createTodo(todo);
    }

    @Put('')
    UpdateTodos(@Body() updatedTodos: Todo[]) {
        return this.todoService.updateMany(updatedTodos);
    }

    @Put(':id')
    UpdateOneTodo(@Param('id') todoId: string, @Body() updatedTodo: Todo) {
        return this.todoService.updateOneById(todoId, updatedTodo);
    }
}

Services

//By default, injectables are singleton
@Injectable()
class TodoService {
    //create  your own DatabaseService to interact with db, it will  be injected
    constructor(databaseService: DatabaseService) {
    }

    getTodos() {
        this.databaseService.getMany();
    }
    // implement your logic
}

Run your app

const optionalPort = 4000;
const app = new DanetApplication();
await app.init(TodoModule);
await app.listen(optionalPort); //default to 3000