Write a small program.
It's on the web in seconds.
Codetje runs WebAssembly: small programs that answer web requests, run on a schedule or send you an email. Write one in your browser, publish it, and it has its own address.
import { Request, Response } from "@codetje/assemblyscript";
export function handle(req: Request): Response {
const name = req.param("name");
const who = name === null ? "world" : name;
return Response.text("Hello, " + who + "!");
}Publish, and it's live.
No servers and nothing to configure. The editor compiles your code in the browser as you type, and publishing puts it on the web in about a second.
Every publish is a version you can go back to. Try it at a preview address first, then make it live for everyone.
- ✓ Built in your browser 152 KiB · 0.4 s
- ✓ Published
0.3.20.6 s - ✓ Live at
frank--weather--preview.codetje.app - Make 0.3.2 live when you're happy with it
An API in a dozen lines.
Your package gets each request and returns a response: route on the method and path, read the body, answer with JSON. Webhooks, small backends and glue between services all fit.
Secrets stay in the package's environment, and it can only fetch from the sites you allow.
import { Request, Response, JSON } from "@codetje/assemblyscript";
export function handle(req: Request): Response {
if (req.method == "GET" && req.path == "/todos") {
return Response.json(JSON.stringify(allTodos()));
}
if (req.method == "POST" && req.path == "/todos") {
const todo = addTodo(req.text());
return Response.json(JSON.stringify(todo), 201);
}
return Response.text("Not found", 404);
}200 application/json
[
{ "id": 1, "text": "Buy stroopwafels", "done": false },
{ "id": 2, "text": "Ship the API", "done": true }
]Pages, not just endpoints.
Return HTML and it's a web page with its own address: a landing page, a status board, a form that emails you what people send. Build it with templates that escape what you put in, or render Markdown with a package someone already wrote.
import { Request, Response, Html, html } from "@codetje/assemblyscript";
export function handle(req: Request): Response {
const up = checkSites();
return Response.html(html`
<h1>Is it up?</h1>
<p>${up.length} of 3 sites are fine.</p>
<ul>${up.map<Html>(row)}</ul>`);
}Is it up?
3 of 3 sites are fine.
- shop.example 142 ms
- blog.example 88 ms
- api.example 203 ms
Run it every morning.
Give a package a schedule and Codetje calls it on time: every hour, every weekday at seven, the first of the month. Check a feed, clean up old data, ping a service.
The schedule belongs to the package, so you can change it without publishing anything.
import { ScheduledEvent, println } from "@codetje/assemblyscript";
// Its schedule, set on its page: 0 7 * * MON-FRI
export function scheduled(event: ScheduledEvent): void {
const fresh = newSince(fetchFeeds(FEEDS), event.scheduled - DAY);
postToChat(fresh);
println(fresh.length.toString() + " new items");
}Weekdays at 07:00 next run Mon 07:00
- ID
weekdays - Cron
0 7 * * MON-FRI - Timezone
Europe/Amsterdam
Email yourself.
Sending yourself an email is one line, as easy as writing to the log. Get a reminder when it's going to rain, a digest of what changed, or an alert when something breaks.
import { ScheduledEvent, sendEmail } from "@codetje/assemblyscript";
export function scheduled(event: ScheduledEvent): void {
const rain = forecast("Amsterdam").rainChance;
if (rain > 50) {
sendEmail("Take an umbrella ☔",
rain.toString() + "% chance of rain today.");
}
}Codetje to frank · 07:00
[frank/umbrella] Take an umbrella ☔
80% chance of rain today.
Use what others made. Share what you make.
Every package can export functions for other packages to import. Need Markdown, QR codes or image resizing? Import it instead of writing it. Your own packages work the same way.
Imports are pinned to a version when you publish, and each one only gets the access you give it.
import { Request, Response } from "@codetje/assemblyscript";
import { render } from "alice/markdown";
import { svg } from "alice/qr";
export function handle(req: Request): Response {
return Response.html(render(NOTES) + svg(LINK, 128));
}- alice/markdown
3.1.0no access needed - alice/qr
1.0.4no access needed
And also
Bring any language
Anything that compiles to a wasi:http component runs here: Rust, Go, C and more. Publish it with rt publish.
Run it, watch the logs
Call any version from its page, with any method and body, and see its logs as requests come in.
Private until you say so
Only you see a package until you make it public. Secrets stay in its environment.
Sandboxed by design
WebAssembly can't touch anything it wasn't given, so a package only does what you allow.
Got a small idea? Ship it tonight.
Recently published All packages
- codetje/docs
0.20.0 - frankvd/test2
0.1.6 - frankvd/hello
0.1.5