Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

tsoa

Package Overview
Dependencies
Maintainers
0
Versions
207
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tsoa

Build swagger-compliant REST APIs using TypeScript and Node

  • 6.6.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
177K
increased by12.44%
Maintainers
0
Weekly downloads
 
Created

What is tsoa?

tsoa is a TypeScript framework for building RESTful APIs. It provides tools to automatically generate OpenAPI documentation and route handlers based on TypeScript interfaces and decorators.

What are tsoa's main functionalities?

Automatic Route Generation

tsoa allows you to define your API routes using TypeScript decorators. The above code defines a route '/users' that returns a list of users.

import { Controller, Get, Route } from 'tsoa';

@Route('users')
export class UserController extends Controller {
  @Get()
  public async getUsers(): Promise<User[]> {
    return [{ id: 1, name: 'John Doe' }];
  }
}

OpenAPI Specification Generation

tsoa can automatically generate OpenAPI specifications and route handlers based on your TypeScript code. This helps in keeping your API documentation up-to-date with your code.

import { generateRoutes, generateSpec } from 'tsoa';

const app = express();

// Generate OpenAPI spec
generateSpec({
  entryFile: './src/server.ts',
  outputDirectory: './dist',
  specVersion: 3
});

// Generate routes
generateRoutes({
  entryFile: './src/server.ts',
  routesDir: './dist'
});

Request Validation

tsoa provides built-in request validation. The above code demonstrates how to validate query parameters using decorators.

import { Controller, Get, Route, Query } from 'tsoa';

@Route('users')
export class UserController extends Controller {
  @Get()
  public async getUsers(@Query() age: number): Promise<User[]> {
    // Validate the 'age' query parameter
    if (age < 0) {
      throw new Error('Age must be a positive number');
    }
    return [{ id: 1, name: 'John Doe', age }];
  }
}

Other packages similar to tsoa

Keywords

FAQs

Package last updated on 08 Dec 2024

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc