Skip to content

Latest commit

 

History

History
151 lines (104 loc) · 3.48 KB

browser-only.md

File metadata and controls

151 lines (104 loc) · 3.48 KB

In-browser playgrounds

Most playgrounds (like Go or MongoDB) run code on the Codapi server.

But there are some playgrounds that work completely in the browser, no Codapi server required.

Note that WASI-based playgrounds (engine = wasi in the examples below) require two additional scripts besides the usual snippet.js:

<script src="https://unpkg.com/@antonz/[email protected]/dist/runno.js"></script>
<script src="https://unpkg.com/@antonz/[email protected]/dist/engine/wasi.js"></script>
<script src="https://unpkg.com/@antonz/[email protected]/dist/snippet.js"></script>

JavaScript

Executes the code using the AsyncFunction.

<pre>
const msg = "Hello, World!"
console.log(msg)
</pre>

<codapi-snippet engine="browser" sandbox="javascript" editor="basic"></codapi-snippet>

Try it

Fetch

Executes the code using the Fetch API.

<pre>
POST https://httpbingo.org/dump/request
content-type: application/json

{
    "message": "hello"
}
</pre>

<codapi-snippet engine="browser" sandbox="fetch" editor="basic"></codapi-snippet>

Try it

Lua

Executes the code using the Lua WASI runtime (330 KB).

<pre>
local msg = "Hello, World!"
print(msg)
</pre>

<codapi-snippet engine="wasi" sandbox="lua" editor="basic"></codapi-snippet>

Try it

PHP

Executes the code using the PHP WASI runtime (13.2 MB).

<pre>
&lt;?php
$msg = "Hello, World!";
echo $msg;
?&gt;
</pre>

<codapi-snippet engine="wasi" sandbox="php" editor="basic"></codapi-snippet>

Try it

PostgreSQL

Executes the code using the PGlite runtime (12 MB).

<pre>
create table data(message text);
insert into data values ('Hello, World!');
select * from data;
</pre>

<codapi-snippet engine="pglite" sandbox="postgres" editor="basic" output-mode="table">
</codapi-snippet>

Try it

Note that this playground requires additional scripts besides the usual snippet.js:

<script type="module">
    import { PGlite } from "https://cdn.jsdelivr.net/npm/@electric-sql/pglite/dist/index.js";
    window.PGlite = PGlite;
</script>
<script src="https://unpkg.com/@antonz/[email protected]/dist/engine/pglite.js"></script>
<script src="https://unpkg.com/@antonz/[email protected]/dist/snippet.js"></script>

Python

Executes the code using the Python WASI runtime (26.3 MB).

<pre>
msg = "Hello, World!"
print(msg)
</pre>

<codapi-snippet engine="wasi" sandbox="python" editor="basic"></codapi-snippet>

Try it

Ruby

Executes the code using the Ruby WASI runtime (24.5 MB).

<pre>
msg = "Hello, World!"
puts msg
</pre>

<codapi-snippet engine="wasi" sandbox="ruby" editor="basic"></codapi-snippet>

Try it

SQLite

Executes the code using the SQLite WASI runtime (2.1 MB).

<pre>
select "Hello, World!" as message;
</pre>

<codapi-snippet engine="wasi" sandbox="sqlite" editor="basic"></codapi-snippet>

Try it