Ergonomic, chaining-based Typescript framework for quick API development for Fastify

Overview
channel banner



Ergonomic, chaining-based Typescript framework for quick API development for Fastify

Installation

> pnpm add @t3ned/channel

Usage

// index.ts

import { Application } from "@t3ned/channel";
import fastify from "fastify";

const server = fastify();
const app = new Application(server)
	.setRouteDirPath(__dirname, "api")
	.setEnvFilePath(process.cwd(), ".env")
	.setDevelopmentEnvName("DEVELOPMENT")
	.setRoutePrefix("/api")
	.setDefaultVersionPrefix("v")
	.setDefaultVersion(1);

app.listen(3000, "0.0.0.0")
	.then(() => console.log(`Listening on port ${app.port}`))
	.catch((error) => console.error(error));
// api/example.ts

import { HttpStatus, ApiError, Get, env } from "@t3ned/channel";
import { z } from "zod";

const getExampleParamsSchema = z.object({
	id: z.string().uuid(),
});

process.env.AUTHORIZATION = "EXAMPLE";

export const getExample = Get("/:id")
	.version(1)
	.status(HttpStatus.Found)
	.params(getExampleParamsSchema)
	.status(HttpStatus.Ok)
	.preHandler((req, _reply, done) => {
		const { authorization } = req.headers;

		if (authorization !== env("AUTHORIZATION")) {
			throw new ApiError() //
				.setCode(0)
				.setStatus(HttpStatus.Unauthorized)
				.setMessage("Unauthorized");
		}

		return done();
	})
	.handler(({ parsed }) => {
		return {
			id: parsed.params.id,
		};
	});
You might also like...

NextAuth.js plugin for Fastify.

fastify-next-auth Authentication plugin for Fastify, powered by NextAuth.js. Requirements: fastify-cookie: used to set cookie for tracking sessions. f

Dec 16, 2022

End-to-End type safety for REST APIs written in Fastify. Only problem is you have to explicity export and register route handlers. LOL

Chino intelligence in japaneese End-to-End type safety for REST APIs written in Fastify. Only problem is you have to explicity export and register rou

Sep 12, 2022

SmartBuilder: A Block-based Visual Programming Framework for Smart Contract Development

SmartBuilder: A Block-based Visual Programming Framework for Smart Contract Development

SmartBuilder A Block-based Visual Programming Framework for Smart Contract Development Technology stack used SmartBuilder Framework - Google Blockly A

Mar 29, 2022

Quick One Liners in JavaScript, TypeScript, Python, Rust, Java, Ruby, C, C++

ONE LINERS This repository contains cool and simple one line utility functions to easily use common repetitive methods in JavaScript, TypeScript, Pyth

Mar 2, 2022

Quick way to start a new TypeScript/Next.js/Firebase web app 😼

Quick way to start a new TypeScript/Next.js/Firebase web app 😼

create-crash-app Template repo to quickly set up an opinionated, strict config, typesafe Next.js project. Get started with create-crash-app by running

Oct 28, 2022

quick.js based sandbox

About quick.js based sandbox npm install define-function works in any WebAssembly environment node browser wechat miniprogram Usage define a function

Dec 7, 2022

Dynamic-web-development - Dynamic web development used CSS and HTML

Dynamic-web-development - Dynamic web development used CSS and HTML

Dynamic-web-development ASSISNMENT I just used CSS and HTML to make a mobile int

Feb 8, 2022

The project integrates workflow engine, report engine and organization authority management background, which can be applied to the development of OA, HR, CRM, PM and other systems. With tlv8 IDE, business system development, testing and deployment can be realized quickly.

The project integrates workflow engine, report engine and organization authority management background, which can be applied to the development of OA, HR, CRM, PM and other systems. With tlv8 IDE, business system development, testing and deployment can be realized quickly.

介绍 项目集成了工作流引擎、报表引擎和组织机构权限管理后台,可以应用于OA、HR、CRM、PM等系统开发。配合使用tlv8 ide可以快速实现业务系统开发、测试、部署。 后台采用Spring MVC架构简单方便,前端使用流行的layui界面美观大方。 采用组件开发技术,提高系统的灵活性和可扩展性;采

Dec 27, 2022

Quick and easy spring animation. Works with other animation libraries (gsap, animejs, framer motion, motion one, @okikio/animate, etc...) or the Web Animation API (WAAPI).

Quick and easy spring animation. Works with other animation libraries (gsap, animejs, framer motion, motion one, @okikio/animate, etc...)  or the Web Animation API (WAAPI).

spring-easing NPM | Github | Docs | Licence Quick and easy spring animations. Works with other animation libraries (gsap, animejs, @okikio/animate, mo

Dec 14, 2022
Comments
  • Fix imports requiring dist

    Fix imports requiring dist

    Problem Importing the package modules (express or fastify) requires /dist in the package name to access the module:

    import { Application } from "channel/dist/express";

    Solution Export a file for each of the modules to remove the /dist prefix import { Application } from "channel/express";

    opened by T3NED 0
Releases(v1.4.2-beta)
Owner
T3NED
Backend Developer
T3NED
An iterator wrapper that supports Rust-style chaining

Riter (in development) An iterator wrapper that supports Rust-style chaining Install TODO: This package is not yet available. Once it's mature enough,

잇창명 3 Mar 3, 2022
Node.js ESM loader for chaining multiple custom loaders.

ESMultiloader Node.js ESM loader for chaining multiple custom loaders. Fast and lightweight No configuration required, but configurable if needed Usag

jhmaster2000 2 Sep 12, 2022
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
API server for AospExtended made with Fastify.

AospExtended API API server for AospExtended made with Fastify. Run Locally Clone the project git clone https://github.com/allstargaurav/aospextende

Gaurav 3 Oct 12, 2022
🔥 Blazing Fast API which scrapes Mydramalist.com made using Fastify and Cheerio.

mydramalist API ?? Blazing Fast API which scrapes Mydramalist.com made using Fastify and Cheerio. Setup pnpm install node index.js available at http:/

Paranjay Singh 6 Dec 4, 2022
Api simples de OCR feita com Fastify e Tesseract.js

ocr-api API de OCR simples feita com Fastify e Tesseract.js Iniciando Depois de instalar as depedências, simplesmente inicia com npm run start. Nota:

Victor Reis David 3 Oct 8, 2022
Run REST APIs in Node.js applications frameworks (Express, Koa, Hapi and Fastify) on top of any Serverless Cloud.

?? Serverless Adapter Install | Usage | Support | Architecture | Credits Run REST APIs and other web applications using your existing Node.js applicat

Vinicius Lourenço 45 Jan 1, 2023
🚀 Blazing Fast S3 Powered CDN ✨ Powered By Fastify, S3 Buckets & Docker!

?? WasiCDN Blazing Fast S3 Powered CDN, Powered By Fastify, S3 Compatible Buckets & Docker! Core DockerHub: https://hub.docker.com/r/maximking19/wasic

Maxim 5 Aug 31, 2022