fadushin / esp8266

This repository contains source code for the ESP8266.
BSD 2-Clause "Simplified" License
73 stars 22 forks source link

Return HTML with http_api_handler #8

Closed imihajlow closed 6 years ago

imihajlow commented 7 years ago

REST is good, but generating HTML pages on-the-fly is also good and useful. Returning a string from the get/post/put/delete methods sends an HTML content-type.

fadushin commented 7 years ago

Nice, let's add a test for this, as well.

imihajlow commented 6 years ago

@fadushin merge pls?

fadushin commented 6 years ago

@imihajlow I'd like to change the return semantics of the API handler, so that by default the handler will return an object that can be translated to JSON, unless the return type is a tuple, in which case the first element of the tuple contains the content type (as a string), and the second contains the data.

This makes the interface cleaner for the target use-case (JSON API), but allows implementors to define their own return types. I find it makes it easier to handle all JSON types (dicts, lists, ints, floats, bools, and strings), whereas when a handler returns string, it always is interpreted as HTML.

It does mean you will need to change your code to adapt to this semantic change.

imihajlow commented 6 years ago

Hi @fadushin, Thanks for notifying, but I don't use micropython in my project anymore due to an unavoidable mbedtls/lwip bug. However, this sounds like a good change.