owlbrain-http
v0.2.0
Published
**HTTP integration for OwlBrain — expose routes, receive requests, and build HTTP calls driven automations with TypeScript.**
Downloads
22
Readme
OwlBrain HTTP
HTTP integration for OwlBrain — expose routes, receive requests, and build HTTP calls driven automations with TypeScript.
This integration lets your OwlBrain scripts react to HTTP requests using simple decorators. It turns incoming HTTP calls into events, allowing to easily mix it up with other sources of events.
List of provided decorators
Script
- @HttpScript — Apply default parameters to the script's events handlers
Events
- @Get — Open a GET endpoint
- @Post — Open a POST endpoint
- @Put — Open a PUT endpoint
- @Patch — Open a PATCH endpoint
- @Delete — Open a DELETE endpoint
Quickstart
Install
npm install owlbrain-core owlbrain-httpEnable the HTTP integration
import { OwlBrain } from "owlbrain-core"
import { HttpIntegration } from "owlbrain-http"
async function main() {
await OwlBrain.withIntegration(new HttpIntegration({ port: 3000 })).run()
}Create a script with HTTP routes
import { Script } from "owlbrain-core"
import { Http, Get, Post } from "owlbrain-http"
@HttpScript({ routePrefix: "/api" })
export class UserScript extends Script {
@Get("/hello")
async hello() {
return {
status: 200,
body: { message: "Hello from OwlBrain!" }
}
}
@Post("/echo")
async echo(event) {
return {
status: 200,
body: { received: event.body }
}
}
}This automatically exposes:
GET /api/helloPOST /api/echo
Examples
You can finds usage examples in the examples/ folder and run them with npm run example <example-name>
- basic — Minimal example
- http-script-decorator — Use the @HttpScript decorator to provide script wide parameters
Also find more examples on owlbrain-core package
