A registry for safe transformation of media types

Context

REST APIs are great in that they can offer machine readability (in the form of structured data) at the same time as human readability (in the form of plain text or generic formats like HTML) – at the same time, thanks to content negotiation.

When a server is not able to offer human readable formats, accessibility suffers. The proposal of a registry for safe media type transformations could mend that gap.

Proposal

Let’s have an online repository of of media type translators. The repository can be browsed online, but also queried by debug tools whenever they encounter data in any given media type.

A media type translator is a program in a safely executable language that provides one single pure function that maps input in one media type to output of another media type. It should be annotated with several properties:

Example use case

An IoT device may have some debug interface through which an authorized user can ask it to run a ping command. In a RESTful context, this is expressed through a resource to which an address is POSTed through CoAP, and a resource created as a response to that POST that contains the latest state of the ping until it expires or is deleted. (There may be pforms involved in setting up the POST, and while a language for them is still under heavy development, this mechanism might even translate those in the first place).

That resource representing a series of pings returns data in CBOR format, and annotates it as application/vnd.riot-os.pingstate+cbor. It looks about like this:

88D8368350FE8000000000020202FFFFFFFE030303F6182A1872187419FFFE03187818C9190960

Without this registry, the best a general command line tool for interacting with REST IoT servers can do is to recognize the structured CBOR suffix, and display the data in diagnostic notation:

[ipv6'fe80::202:2ff:ffff:fe03:0303%42', 114, 116, 65534, 3, 120, 201, 2400]

However, if there were suitable CDDL around, the tool could look up the provided media type in the registry, and the data could be shown in an annotated way:

[
    /destination/ ipv6'fe80::202:2ff:ffff:fe03:0303%42',
    /received/    114,
    /sent/        116,
    /recent/   0xfffe,
    /late/          3,
    /min/         120 /ms/,
    /avg/         201 /ms/,
    /max/        2400 /ms/
]

which is already a great improvement, and only required that someone iled the CDDL that is part of the definition of application/vnd.riot-os.pingstate+cbor into the database.

If, instead, they wrote a small script to convert to plain text, all of a sudden a generic IoT debug tool with no prior knowledge of the precise data format would be able to produce good output without any steps that’d be taxing on the IoT device:

Ping to fe80::202:2ff:ffff:fe03:0303%42

...............>

116 packets transmitted, 114 received, 2% packet loss
rtt min/avg/max = 120/201/2400 ms
3 packets received late (possibly duplicates)

If a similar generic client were implemented in a browser instead of a command line tool, it would prefer translators that produce HTML over those that produce plain text, and might render this in a more visually appealing way.

Extensions

Idea incubator summary

I think this could be set up in a weekend. I don’t have a weekend right now.


This page is part of chrysn's public personal idea incubator; go up for its other entries, or read about the idea of having an idea incubator for more information on what this is.