Using the Action Handler
The Action handler is a simple Appweb handler that processes requires by invoking registered C functions. The action handler is ideal for situations when you want to generate a simple response using C code. The action handler employs a direct mapping from URIs to C functions with no further parsing or analysis of the URI than that provided by the Appweb router.
Registering Actions
Actions are registered by calling httpDefineAction and providing the function to run and the corresponding URI.
static void hello(HttpStream *stream) { httpWrite(stream, "Hello World\n"); httpFinalize(stream); } httpDefineAction("/action/hello", hello);
The httpDefineAction call registers the hello C function to be invoked whenever the /action/hello URI is requested.
Actions
An action routine is responsible for rendering a complete response to the client. A response is concluded by calling httpFinalize. If you cannot yet complete the response without waiting, it is best not to block, as this will consume a thread from the worker pool while waiting. Instead, return from the action without calling httpFinalize and arrange for the response to be completed later. Note: that the Appweb RequestTimeout and InactivityTimeout in appweb.conf may terminate a long running request. If you need to extend these timeouts for a request, call httpSetTimeout.
Appweb API
The Appweb Native APIs consist of C language headers, function prototypes, structure definitions and defines. They are divided into three API groups. You can use many of these APIs from within Action routines.
Area | Description |
---|---|
Appweb | Appweb Http API |
Http | Http Client and Server Library API |
MPR | Multithreaded Platform Runtime API |