Nanyx
PlaygroundPackages

Files, HTTP and JSON

What is still open for the file system, HTTP and JSON packages

The file system, the HTTP client and the HTTP host are built, as shipped packages, and JSON as nanyx.json, published to the package index from nanyx-lang/json. What a program uses is in the user docs: filesystem, file, dir and path for nanyx.fs; client, http, request and response for nanyx.http.core; The HTTP host and the HTTP server cookbook for nanyx.http; and json, decoders and encoders for nanyx.json. How the hosts implement them is on Hosts and Foreign functions. This page keeps what is still open.

The file system

  • More than one --allow-dir. The CLI’s option parser takes one value per option, so nanyx run takes one extra directory; WasmRunner takes any number.
  • A test host that provides FileSystem in memory, with Testing.

HTTP

  • Binary bodies. A body is a string, because nothing in the library turns an Array(U8) into a string. Binary bodies come with a conversion between bytes and text.
  • A .json helper. Response.json would make nanyx.http.core depend on nanyx.json, and the HTTP host would want a constructor of that name as much as a client wants a reader. Whether to add it is open.
  • What the HTTP host still needs, route patterns, Log and Env, streamed bodies, serving beyond localhost and serving as a wasi:http component, is on Serving HTTP.

JSON

  • Encoding and decoding any record automatically (#1789) is decided to wait for type reflection (Type members and reflection), which lets any library walk a type’s structure, not just JSON’s. Deriving a JSON context in the compiler, as Eq and ToString are derived, was rejected: it would be a compiler special case that a SQL or YAML library couldn’t use.
  • Where the encoders live. They are in a module of their own, nanyx.json/encode, because their names are the decoders’ (encode.string, json.string). Attaching them to Encoder (json.Encoder.string) would keep one module, since a type’s attached definitions are reached through an import’s alias (#1833); whether to move them is open.
  • The decoders’ file. They are in json.typed.nyx, part of the module json. A partial module’s file can name a type from a file that sorts after it (#1838), so they could be laid out in other files; whether to is open.

Open questions

  • Package names. nanyx.fs, nanyx.http.core, nanyx.http and nanyx.json are working names, as the console packages’ are (Hosts).