iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🪃

Implementing an HTTP Server in Uiua

に公開
2023/10/01

https://zenn.dev/hatappo/articles/11c7ca2bc2d98e

Continuation of the above.

Uiua has built-in support for Audio and Images. Since it can also handle TCP sockets, you can even write an HTTP server. There is a sample in the official repository, so let's try running it.

https://github.com/uiua-lang/uiua/blob/main/examples/http_server.ua

Following the comments, run trunk in the site folder of the cloned repository.

trunk build --release

By the way, Trunk seems to be a tool for compiling and bundling WASM web applications written in Rust. It feels similar to something like webpack, though it generates WASM binaries as well as JS.

https://trunkrs.dev/

Error:

   Compiling wasm-bindgen v0.2.87
error[E0463]: can't find crate for `core`
  |
  = note: the `wasm32-unknown-unknown` target may not be installed
  = help: consider downloading the target with `rustup target add wasm32-unknown-unknown`

It seems like a compilation target is missing.

$ rustup target list --installed
aarch64-apple-darwin
x86_64-unknown-linux-gnu
x86_64-unknown-linux-musl

Indeed.
Adding it.

$ rustup target add wasm32-unknown-unknown
info: downloading component 'rust-std' for 'wasm32-unknown-unknown'
info: installing component 'rust-std' for 'wasm32-unknown-unknown'
$ rustup target list --installed
aarch64-apple-darwin
wasm32-unknown-unknown
x86_64-unknown-linux-gnu
x86_64-unknown-linux-musl

Looks good.
Again,

$ trunk build --release

....

   Compiling uiua v0.0.5 (/Users/xxxx/uiua)
   Compiling site v0.1.0 (/Users/xxxx/uiua/site)
    Finished release [optimized] target(s) in 1m 25s
2023-09-30T10:55:48.736405Z  INFO fetching cargo artifacts
2023-09-30T10:55:49.104612Z  INFO processing WASM for site
2023-09-30T10:55:49.116124Z  INFO downloading wasm-bindgen version="0.2.87"
2023-09-30T10:55:51.999547Z  INFO installing wasm-bindgen
2023-09-30T10:55:52.061216Z  INFO calling wasm-bindgen for site
2023-09-30T10:55:52.469286Z  INFO copying generated wasm-bindgen artifacts
2023-09-30T10:55:52.471213Z  INFO applying new distribution
2023-09-30T10:55:52.471898Z  INFO ✅ success

It passed.
However, I'm not quite sure what was generated. It looks like the artifacts were generated around target/wasm-bindgen/release/.

$ cd ../
$ uiua run examples/http_server.ua
Server started

Opening http://localhost:8080 confirms that the same web page as the official site is indeed displayed.
Logs are being output in the terminal where the server was started.

$ uiua run examples/http_server.ua
Server started
Request:
/
Response:
3019 bytes
Request:
/styles-c706be319f8bf9ff.css
Response:
11629 bytes
Request:
/site-8907d00a07aaa18c.js
Request:
/site-8907d00a07aaa18c_bg.wasm
Request:
/uiua-logo.png
Response:
42998 bytes
Response:
28348 bytes
Request:
/DejaVuSans.ttf
Response:
757143 bytes
Response:
7096460 bytes
Request:
/favicon.ico
Response:
2303 bytes
Request:
/DejaVuSansMono.ttf
Response:
335135 bytes

So it seems that most of the content is written in Rust, and the web server is running what was written in Uiua. That's impressive.

Impressions

A major difference from other languages is that I have absolutely no clue what is going on just by looking at the http_server.ua code. Without knowing the reserved words (or rather, the glyphs), I have to hover over each glyph to check what token it is, so it is still difficult for me to just skim through it. That said, I can definitely see that the code looks quite cute.

Continued in:

https://zenn.dev/hatappo/articles/7e4c167aa1837d

Discussion