All Projects → SampaioLeal → destjs

SampaioLeal / destjs

Licence: other
Make beautiful APIs with the NestJS inspired framework for Deno

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to destjs

deno-pokemon
a simple api to create and explore pokemons - made with oak deno framework
Stars: ✭ 20 (-35.48%)
Mutual labels:  oak, deno
Oak
A middleware framework for handling HTTP with Deno 🐿️ 🦕
Stars: ✭ 3,799 (+12154.84%)
Mutual labels:  oak, deno
deno rest
A Boilerplate for deno RESTful apis
Stars: ✭ 74 (+138.71%)
Mutual labels:  oak, deno
superdeno
Super-agent driven library for testing Deno HTTP servers.
Stars: ✭ 119 (+283.87%)
Mutual labels:  oak, deno
oak-middleware-jwt
Oak middleware for JWT
Stars: ✭ 24 (-22.58%)
Mutual labels:  oak, deno
typeorm
Forked from https://github.com/typeorm/typeorm
Stars: ✭ 107 (+245.16%)
Mutual labels:  deno
nestjs-redis
Redis(ioredis) module for NestJS framework
Stars: ✭ 112 (+261.29%)
Mutual labels:  nestjs
dothq.co
This repository has moved to:
Stars: ✭ 17 (-45.16%)
Mutual labels:  nestjs
awesome-nestjs
A curated list of awesome things related to NestJS 😎
Stars: ✭ 5,771 (+18516.13%)
Mutual labels:  nestjs
deno-playground
play.golang.org, but built in deno, and for deno.
Stars: ✭ 57 (+83.87%)
Mutual labels:  deno
nestjs-graphql-serverless
Boilerplate for using NestJS with GraphQL (Code-First) on serverless environment (AWS Lambda)
Stars: ✭ 64 (+106.45%)
Mutual labels:  nestjs
Netrex
A powerful minecraft bedrock software written in Rust with a powerful Typescript plugin API.
Stars: ✭ 35 (+12.9%)
Mutual labels:  deno
nestjs-prisma-docker
Dockerizing a NestJS app with Prisma and PostgreSQL
Stars: ✭ 42 (+35.48%)
Mutual labels:  nestjs
cors
Deno.js CORS middleware.
Stars: ✭ 46 (+48.39%)
Mutual labels:  deno
discord-api-types
Up to date Discord API Typings, versioned by the API version
Stars: ✭ 270 (+770.97%)
Mutual labels:  deno
nest-blog-api
B站全栈之巅:基于TypeScript的NodeJs框架:NestJs开发博客API (node.js+nest.js)
Stars: ✭ 34 (+9.68%)
Mutual labels:  nestjs
nestx-log4js
nestjs log4js-node module
Stars: ✭ 21 (-32.26%)
Mutual labels:  nestjs
eslint-plugin-nestjs
POC. ESLint rules for nestjs framework
Stars: ✭ 30 (-3.23%)
Mutual labels:  nestjs
mapped-types
Configuration module for Nest framework (node.js) 🐺
Stars: ✭ 192 (+519.35%)
Mutual labels:  nestjs
heroku-buildpack-deno
Heroku Buildpack for Deno
Stars: ✭ 72 (+132.26%)
Mutual labels:  deno

DestJS

Make beautiful APIs with the NestJS inspired framework for Deno

CodeFactor deno.land/x

Goals

Goal State
Controllers store and routes creation with Decorators Complete
Other methods decorators (PUT, DELETE, POST, PATCH) Complete
Global Middlewares folder and management Complete
Interceptors for methods Complete
Input validation Complete
Context Helpers In Progress
Format endpoint paths In Progress
Logger Waiting
Create example repository Waiting
Create documentation Waiting
Handle OPTIONS and HEAD Waiting
DestJS CLI Waiting
Dynamic Configs Class Waiting

Example Project

To get started with DestJS you have to instatiate the app with the createApp function and build a minimal structure to the framework works properly. At the root of your project you need to create two folders: controllers and middlewares They will take care of your controllers and middlewares that run in every request

// main.ts
import { createApp } from "./deps.ts";

createApp({
  port: 8000,
});
// deps.ts
export { createApp } from "https://deno.land/x/[email protected]/mod.ts";

This will initialize things and configure then before creating a new oak server. Take alook at what DestJS will do:

  • Read the controllers folder at the root of your project and store them with methods interceptors
  • Read the middlewares folder at the root of your project and store them
  • Configure stored middlewares to oak Application
  • Configure stored controllers to oak Router with interceptors
  • Start oak server at specified port

Creating your first Controller

By default DestJS will look at *.controller.ts files at controllers folder and initialize them in order to decorators works as expected. So, let's create a CatsController:

// controllers/cats.controller.ts
import { Controller, Get, HttpContext } from "../deps.ts";

@Controller("/cats")
export default class CatsController {
  @Get("/")
  getOne(context: HttpContext) {
    console.log(context.state);
    return { name: "Michael Scott", cute: true, crazy: true };
  }
}
// deps.ts
export { createApp, Controller, Get } from "https://deno.land/x/[email protected]/mod.ts";
export type { HttpContext } from "https://deno.land/x/[email protected]/types.ts";

Now we can start our API and test the endpoint /cats by running the following command:

deno run --allow-net --allow-read ./main.ts

Creating your first Middleware

By default DestJS will look at *.middleware.ts files at middlewares folder and initialize them in order to decorators works as expected.

Have in mind that middlewares will intercept every request and can manipulate the context and throw errors that will be catched by module middleware handler, returning an Internal Server Error to the client or a custom error using `HttpError class.

So, let's create a DateMiddleware that will inject the actual Date in request state:

// middlewares/date.middleware.ts
import {
  Middleware,
  DestMiddleware,
  HttpContext,
  NextFunction,
} from "../deps.ts";

@Middleware()
export class DateMiddleware implements DestMiddleware {
  use(context: HttpContext) {
    context.state.nowMiddleware = Date.now();
  }
}
// deps.ts
export { createApp, Controller, Get, Middleware } from "https://deno.land/x/[email protected]/mod.ts";
export type {
  DestMiddleware,
  HttpContext,
  NextFunction,
} from "https://deno.land/x/[email protected]/types.ts";

Now we can start our API and test the endpoint /cats. Looking at the terminal we can see the state with a nowMiddleware key with the actual time.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].