Basic Example
A simple example demonstrating Vegaa's core features.
Code
import { vegaa, route } from 'vegaa'
// Simple route
route('/ping').get(() => {
return { message: 'pong' }
})
// Route with parameters
route('/users/:id').get((id) => {
return { userId: id, name: `User ${id}` }
})
// Start server
async function main() {
await vegaa.startVegaaServer({ port: 4000 })
console.log('✅ Server running on http://localhost:4000')
}
main().catch(err => {
console.error('💥 Server failed:', err)
process.exit(1)
})
Try It
What's Happening
- Simple Route -
/pingreturns a JSON response - Route Parameters -
/users/:idextracts theidparameter automatically - Server Start -
startVegaaServer()starts the server on port 4000
Test It
# Start the server
node basic.js
# Test the endpoints
curl http://localhost:4000/ping
# {"message":"pong"}
curl http://localhost:4000/users/123
# {"userId":"123","name":"User 123"}
Key Concepts
- Automatic Parameter Injection -
idis automatically extracted from the route - JSON Responses - Just return an object, Vegaa handles the rest
- Simple API - No
req/resboilerplate
Next Steps
- Try the CRUD Example
- Learn about Parameter Injection