Security News
Bun 1.2 Released with 90% Node.js Compatibility and Built-in S3 Object Support
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
@tsoa/runtime
Advanced tools
@tsoa/runtime is a runtime library for the TSOA framework, which is used to build TypeScript-based REST APIs with OpenAPI documentation. It provides decorators and utilities to define API routes, request validation, and response handling.
Route Definition
Defines a route for the 'users' endpoint and a GET method to retrieve users.
import { Controller, Get, Route } from '@tsoa/runtime';
@Route('users')
export class UserController extends Controller {
@Get()
public async getUsers(): Promise<User[]> {
return [{ id: 1, name: 'John Doe' }];
}
}
Request Validation
Defines a POST method to create a user with request body validation.
import { Controller, Post, Route, Body } from '@tsoa/runtime';
interface CreateUserRequest {
name: string;
}
@Route('users')
export class UserController extends Controller {
@Post()
public async createUser(@Body() request: CreateUserRequest): Promise<User> {
return { id: 1, name: request.name };
}
}
Response Handling
Defines a GET method to retrieve a user by ID with custom response handling for 404 status.
import { Controller, Get, Route, Response } from '@tsoa/runtime';
@Route('users')
export class UserController extends Controller {
@Get('{userId}')
@Response(404, 'User not found')
public async getUser(userId: number): Promise<User> {
if (userId !== 1) {
this.setStatus(404);
return null;
}
return { id: 1, name: 'John Doe' };
}
}
Express is a minimal and flexible Node.js web application framework that provides a robust set of features for web and mobile applications. Unlike @tsoa/runtime, Express does not provide built-in support for TypeScript decorators or OpenAPI documentation.
NestJS is a progressive Node.js framework for building efficient, reliable, and scalable server-side applications. It uses TypeScript and supports decorators similar to @tsoa/runtime, but it also includes a broader set of features like dependency injection and a modular architecture.
Hapi is a rich framework for building applications and services in Node.js. It provides powerful configuration options and a plugin-based architecture. Unlike @tsoa/runtime, Hapi does not natively support TypeScript decorators or OpenAPI documentation.
This package contains the runtime helpers for tsoa.
For a comprehensive Readme, please refer to the main readme.
FAQs
Build swagger-compliant REST APIs using TypeScript and Node
The npm package @tsoa/runtime receives a total of 168,261 weekly downloads. As such, @tsoa/runtime popularity was classified as popular.
We found that @tsoa/runtime demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.