To create a dynamic library bin compatible with this server, you must implement a callback function with the following signature:
CwebHttpResponse *request_handler(CwebHttpRequest *request, int argc, char *argv[]);- Parameters:
request: HTTP request object from the CWebStudio framework.argcandargv: Command line arguments passed to the server, allowing the library to access global configurations.
- Return: A
CwebHttpResponseobject with the HTTP response to be sent to the client.
Basic Example: Simple Hello World Handler using CWebStudioOne.c
Below is a basic example of a dynamic library that responds with a "Hello, World!" message for any HTTP request. This is a minimal implementation to help you get started.
#include "CWebStudioOne.c"
CwebHttpResponse *request_handler(CwebHttpRequest *request, int argc, char *argv[]) {
CwebNamespace cweb = newCwebNamespace();
return cweb.response.send_text("Hello, World!", 200);
}Compile your library as .dll (Windows) or .so (Linux) using a command like:
- Linux:
gcc -shared -fPIC -o mylib.so mylib.c- mingw:
i686-w64-mingw32-gcc -fPIC -shared -o mylib.dll mylib.c -lws2_32Then, pass its path and the callback function name via CLI when starting the server:
CWebFirmware --port 5000 --dynamic_lib mylib.so --callback request_handler --password mysupersecretpasswordThis basic example shows how to create a simple dynamic library that returns a static response. You can expand on this by adding logic to handle different routes, methods, or request parameters as needed for your application.