Functions (Deno)
Serverless TypeScript functions on your own server. Write, deploy, and invoke via HTTPS.
Creating a Function Server
To create a new function runtime:
- Navigate to Function Servers in the sh0 dashboard.
- Click Create Function Server.
- Enter a name (e.g., "my-api-functions").
- Click Create. sh0 deploys a Deno runtime instance with auto-SSL.
Each function server uses approximately 256 MB of memory and is accessible at https://<name>.sh0.app.
Writing Functions
Functions use the standard Web API pattern: a default export that receives a Request and returns a Response.
Request Object
The Request object is the standard Web API Request. Access:
req.method-- HTTP method (GET, POST, etc.)req.url-- full request URLreq.headers-- request headersawait req.json()-- parse JSON bodyawait req.text()-- raw body text
Response Object
Return a standard Web API Response. You can return any content type:
Deploying
Deploy your function by uploading the TypeScript/JavaScript file via:
- Dashboard -- paste or upload your function file in the function server detail page.
- API -- POST the function code to the sh0 API endpoint for your function server.
Deno compiles and caches the function on the first request. Subsequent requests are served from the cache.
.ts and deploy.Invoking
Call your function at its HTTPS endpoint:
Using npm Packages
Deno supports importing npm packages directly using the npm: specifier:
You can also import from URLs (https://deno.land/x/...) or use import maps for cleaner imports.
Connecting to Databases
Your functions can connect to any database server managed by sh0. Use the internal Docker network hostname for fast, local connections: