dtex / j5e

Framework for embedded devices using ECMA-419, the ECMAScript® embedded systems API specification, based on Johnny-Five's API
https://www.j5e.dev/
MIT License
64 stars 6 forks source link

Should j5e include an http client/server module(s)? #53

Open dtex opened 4 years ago

dtex commented 4 years ago

The IOCP defines TCP Socket classes that can be used for this, and like the other classes, they are low level. When I've built things with J5 that interacted with the world over wifi I always found creating/writing the server to be more of a chore than controlling the hardware itself. Given that, does it make sense to include a barebones HTTP client/server module and possibly a simple router too?

It could be a minimal subset of the node.js HTTP or HTTP2 API.

Not sure this is even doable in a small enough module, but it sure would be nice to make this easier for people.

phoddie commented 4 years ago

To be clear, i have no opinion on what j5e should incorporate. I do have some experience with network protocols on embedded devices, so i'm just responding to 'what is doable" with the hope that what I have to share may be helpful in your decision.

The Moddable SDK contains support for lots of network protocols, including;

Those are all written in JavaScript on top of the Moddable SDK's TCP and UDP sockets. (There are some small exceptions where a native function is used for performance, but that's a detail) The IO Class Pattern's TCP and UDP sockets are (more or less) functionally equivalent to the Moddable SDK. These all run on ESP8266 (and ESP32, Qualcomm QCA4020, macOS, Windows, and Linux).

It should be possible to re-host the Moddable SDK network protocol implementations on the IO Class Pattern version. That's something I hope to try, once I have a chance to update the ESP8266 implementation of the IO Class Pattern to match changes made to the specification over the last year.

The network protocol implementations in the Moddable SDK are minimal, to respect the resources of the device. They are more like protocol parsers and serializers than a friendly developer API. For an environment like j5e, they would feel bizarre. But, like you have done with the IO Class Pattern already, you could build up from there to support the protocols you wish with the API style you prefer.

Finally, the Moddable SDK also has a secure socket client (TLS). This may be used with the HTTP, MQTT, and WebSocket clients. It is a layer on top of the TCP socket and so should also be easily adapted to the IO Class Pattern implementation of TCP socket.