Skip to main content

API Reference

Complete API reference for Vegaa.

Core API

vegaa

The global Vegaa application instance.

import { vegaa } from 'vegaa'

Methods

vegaa.startVegaaServer(options?)

Starts the Vegaa server.

await vegaa.startVegaaServer({
port: 4000, // Port number (default: 4000)
cluster: false // Enable cluster mode (default: false)
})
vegaa.middleware(middleware)

Adds global middleware.

vegaa.middleware(() => ({ user: { id: 1 } }))
vegaa.middleware([middleware1, middleware2])
vegaa.plugin(plugin, options?)

Registers a plugin.

await vegaa.plugin(corsPlugin)
await vegaa.plugin(staticPlugin, { root: './public' })

route(path)

Creates a route builder.

import { route } from 'vegaa'

route('/users/:id')
.get(handler)
.post(handler)
.put(handler)
.delete(handler)
.middleware(middleware)

HTTP Methods

  • .get(handler) - GET request
  • .post(handler) - POST request
  • .put(handler) - PUT request
  • .patch(handler) - PATCH request
  • .delete(handler) - DELETE request
  • .options(handler) - OPTIONS request
  • .head(handler) - HEAD request

Middleware

  • .middleware(middleware) - Route-specific middleware

Express Compatibility

enableExpressCompat(app)

Enables Express middleware compatibility.

import { enableExpressCompat } from 'vegaa'

enableExpressCompat(vegaa)

vegaa.useExpressMiddleware(middleware)

Uses Express middleware (after enabling compatibility).

vegaa.useExpressMiddleware(helmet())
vegaa.useExpressMiddleware('/api', cors())

Response Helpers

html(content)

Returns HTML response.

import { html } from 'vegaa'

route('/').get(() => html('<h1>Hello</h1>'))

text(content)

Returns text response.

import { text } from 'vegaa'

route('/status').get(() => text('OK'))

Plugins

corsPlugin

CORS support plugin.

import { corsPlugin } from 'vegaa'

await vegaa.plugin(corsPlugin)

bodyParserPlugin

Body parsing plugin.

import { bodyParserPlugin } from 'vegaa'

await vegaa.plugin(bodyParserPlugin)

jsonPlugin

JSON formatting plugin.

import { jsonPlugin } from 'vegaa'

await vegaa.plugin(jsonPlugin)

staticPlugin

Static file serving plugin.

import { staticPlugin } from 'vegaa'

await vegaa.plugin(staticPlugin, {
root: './public',
prefix: '/assets'
})

httpClientPlugin

HTTP client plugin.

import { httpClientPlugin } from 'vegaa'

await vegaa.plugin(httpClientPlugin, { timeout: 5000 })

Handler Functions

Handler functions receive parameters based on their names:

  • Route parameters: id, userId, etc.
  • Query parameters: query
  • Request body: body
  • Route params object: params
  • Middleware values: Any middleware-provided value names
route('/users/:id').get((id, query, user) => {
// id → route parameter
// query → query string object
// user → from middleware
})

Error Handling

Throw errors in handlers or middleware:

route('/protected').get(() => {
throw new Error('Unauthorized')
})

TypeScript Support

Vegaa includes full TypeScript support:

import { vegaa, route } from 'vegaa'

route('/users/:id').get((id: string) => {
return { userId: id }
})