1.4.2-beta • Published 2 years ago

@t3ned/channel v1.4.2-beta

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
2 years ago

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,
		};
	});
1.4.2-beta

2 years ago

1.4.1-beta

2 years ago

1.4.0-beta

2 years ago

1.3.0-beta

2 years ago

1.2.1-beta

2 years ago

1.2.0-beta

2 years ago

1.1.2-beta

2 years ago

1.1.1-beta

2 years ago

1.1.0-beta

2 years ago

1.0.0-beta

2 years ago

1.0.13-alpha

2 years ago

1.0.12-alpha

2 years ago

1.0.11-alpha

2 years ago

1.0.10-alpha

2 years ago

1.0.9-alpha

2 years ago

1.0.8-alpha

2 years ago

1.0.7-alpha

2 years ago

1.0.6-alpha

2 years ago

1.0.5-alpha

2 years ago

1.0.4-alpha

2 years ago

1.0.3-alpha

2 years ago

1.0.2-alpha

2 years ago

1.0.1-alpha

2 years ago

1.0.0-alpha

2 years ago