Quickstarts
Quickstart: Edge Functions
Write, deploy and invoke a Deno function.
Functions are serverless TypeScript (Deno) next to your database.
Variables used below: $HOSTBASE_TOKEN (access token), $REF (project ref). SDKs: @hostbase/management (TypeScript) and hostbase_management (Python); full reference at /docs/api.
1. Set a secret and deploy
Secrets are available as environment variables.
curl -X PUT https://host.ulewicz.space/api/v1/projects/$REF/secrets -H "Authorization: Bearer $HOSTBASE_TOKEN" -H "Content-Type: application/json" -d '{"secrets":{"GREETING":"hello"}}'
curl -X PUT https://host.ulewicz.space/api/v1/projects/$REF/functions/hello -H "Authorization: Bearer $HOSTBASE_TOKEN" -H "Content-Type: application/json" \
-d '{"code":"Deno.serve(() => new Response(Deno.env.get(\"GREETING\")));"}'await hb.setSecrets({ ref, body: { secrets: { GREETING: "hello" } } });
await hb.deployFunction({ ref, name: "hello", body: { code: 'Deno.serve(() => new Response(Deno.env.get("GREETING")));' } as never });hb.set_secrets(ref=ref, body={"secrets": {"GREETING": "hello"}})
hb.deploy_function(ref=ref, name="hello", body={"code": 'Deno.serve(() => new Response(Deno.env.get("GREETING")));'})hostbase secrets set GREETING=hello
hostbase functions deploy hello2. Invoke
curl https://abcdefghijklmnopqrst.host.ulewicz.space/functions/v1/hello -H "Authorization: Bearer $ANON_KEY"const { data } = await supabase.functions.invoke("hello");supabase.functions.invoke("hello")3. Logs and versions
Roll back to a previous version with one call.
curl "https://host.ulewicz.space/api/v1/projects/$REF/functions/hello/logs?lines=50" -H "Authorization: Bearer $HOSTBASE_TOKEN"
curl -X POST https://host.ulewicz.space/api/v1/projects/$REF/functions/hello/versions -H "Authorization: Bearer $HOSTBASE_TOKEN" -H "Content-Type: application/json" -d '{"rollback_to":1}'await hb.getFunctionLogs({ ref, name: "hello", query: { lines: 50 } });
await hb.rollbackFunction({ ref, name: "hello", body: { rollback_to: 1 } });hb.get_function_logs(ref=ref, name="hello", query={"lines": 50})
hb.rollback_function(ref=ref, name="hello", body={"rollback_to": 1})hostbase functions logs helloNext: /docs/edge-functions.