Getting Started
Getting Started
Section titled “Getting Started”Welcome to Veloce-TS! This guide will help you get up and running quickly with the latest features and improvements.
:::tip What’s New in v0.2.6
- Fixed
@Querydecorator - Now properly extracts query parameters - Improved GraphQL decorators - No more naming conflicts with HTTP decorators
- Enhanced type safety - Better TypeScript support throughout the framework :::
Installation
Section titled “Installation”Install Veloce using your preferred package manager:
# Using Bun (recommended)bun add veloce-ts zod
# Using npmnpm install veloce-ts zod
# Using pnpmpnpm add veloce-ts zodQuick Start
Section titled “Quick Start”Create your first API in minutes:
import { VeloceTS, Controller, Get, Post, Body, Query, Param } from 'veloce-ts';import { z } from 'zod';
// Define schemasconst UserSchema = z.object({ name: z.string().min(2), email: z.string().email(),});
// Create a controller@Controller('/users')class UserController { @Get('/') async getUsers(@Query() query: any) { const { limit = 10, offset = 0 } = query; return { users: [ { id: 1, name: 'John Doe', email: 'john@example.com' }, { id: 2, name: 'Jane Smith', email: 'jane@example.com' }, ], pagination: { limit, offset, total: 2 } }; }
@Get('/:id') async getUser(@Param('id') id: string) { return { id: parseInt(id), name: 'John Doe', email: 'john@example.com' }; }
@Post('/') async createUser(@Body(UserSchema) user: z.infer<typeof UserSchema>) { return { id: 3, ...user }; }}
// Create and start the appconst app = new VeloceTS({ title: 'My API', version: '1.0.0'});app.include(UserController);app.listen(3000);
console.log('Server running on http://localhost:3000');TypeScript Configuration
Section titled “TypeScript Configuration”Add these settings to your tsconfig.json:
{ "compilerOptions": { "experimentalDecorators": true, "emitDecoratorMetadata": true, "target": "ES2022", "module": "ESNext", "moduleResolution": "bundler" }}Project Structure
Section titled “Project Structure”A typical Veloce-TS project structure:
my-api/├── src/│ ├── controllers/│ │ └── user.controller.ts│ ├── services/│ │ └── user.service.ts│ ├── schemas/│ │ └── user.schema.ts│ └── index.ts├── package.json└── tsconfig.jsonUsing the CLI
Section titled “Using the CLI”Veloce-TS includes a powerful CLI tool:
# Create a new projectveloce-ts new my-api --template rest
# Start development serverveloce-ts dev
# Build for productionveloce-ts build
# Generate OpenAPI specveloce-ts generate openapiNext Steps
Section titled “Next Steps”- Learn about Decorators
- Explore Dependency Injection
- Check out Plugins
- Read the API Reference