OpenWrt Forum Archive

Topic: Lua uhttpd API

The content of this topic has been archived on 2 May 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

I posted this on the General list earlier today, but am thinking it probably belonged on the developer list. So here goes...

I am successfully using uhttpd-mod-lua to run a Lua http handler I am developing--basically, a RESTful service. I can't seem to find where the uhttpd Lua API is documented (formally or otherwise). I've search the OpenWRT codebase, I've searched the Internet...nothing. I'm sure it'll end up being under my nose.
Right now, my handler is making uhttpd.send(...) calls successfully, but I need to find out what other methods I can use. E.g., I'm trying to set an HTTP status code other than 200 (OK) in the response message, but can't seem to do that directly by calling uhttpd.send().

The only reason I know about the send method is because of sample code on the Internet. Surely there's got to be more, and it has to have some documentation (even if only as code comments), right?

You should use ubus and use uhttpd-mod-ubus. It is much easier and you end up with ubus json services that can be used by any application on the router.

mkschreder wrote:

You should use ubus and use uhttpd-mod-ubus. It is much easier and you end up with ubus json services that can be used by any application on the router.

Thanks. I did some quick research and it looks like uhttpd-mod-ubus is limited to sending POST requests. If so, it's not really applicable to my situation, since RESTful APIs can use any and all http methods (verbs): GET, POST, PUT, DELETE, etc...

My source: http://wiki.openwrt.org/doc/techref/ubus

Besides, I don't have the luxury of switching gears at this point. So, question is still open.

Update:

It occurred to me to dump the 'uhttpd' object (table) to see what functions it has. It has:

   recv
   send
   sendc
   urldecode
   urlencode

Googling those names led me to their C implementation here:

   https://dev.openwrt.org/browser/trunk/p … ?rev=31570

While the API isn't documented, the code is easy enough to understand. I think I'll figure out what I need to from here.

The discussion might have continued from here.