c语言REST编程,Ulfius -- 用于开发REST API应用的C语言Web框架

Ulfius是一个基于GNU Libmicrohttpd、Jansson和Libcurl的C语言HTTP框架,适用于开发REST应用,尤其适合内存有限的嵌入式系统。它支持HTTP/HTTPS、数据流和WebSocket。通过示例展示了如何创建一个简单的“Hello World!”应用,并介绍了Ulfius的主要特性,包括安装、版本更新以及与其他项目的集成。
摘要由CSDN通过智能技术生成

Ulfius

HTTP Framework for REST Applications in C.

Based on GNU Libmicrohttpd for the backend web server, Jansson for the json manipulation library, and Libcurl for the http/smtp client API.

Used to facilitate creation of web applications in C programs with a small memory footprint, as in embedded systems applications.

You can create webservices in HTTP or HTTPS mode, stream data, or implement server websockets.

Hello World! example application

The source code of a hello world using Ulfius is the following:

/**

* test.c

* Small Hello World! example

* to compile with gcc, run the following command

* gcc -o test test.c -lulfius

*/

#include

#include

#define PORT 8080

/**

* Callback function for the web application on /helloworld url call

*/

int callback_hello_world (const struct _u_request * request, struct _u_response * response, void * user_data) {

ulfius_set_string_body_response(response, 200, "Hello World!");

return U_CALLBACK_CONTINUE;

}

/**

* main function

*/

int main(void) {

struct _u_instance instance;

// Initialize instance with the port number

if (ulfius_init_instance(&instance, PORT, NULL, NULL) != U_OK) {

fprintf(stderr, "Error ulfius_init_instance, abort\n");

return(1);

}

// Endpoint list declaration

ulfius_add_endpoint_by_val(&instance, "GET", "/helloworld", NULL, 0, &callback_hello_world, NULL);

// Start the framework

if (ulfius_start_framework(&instance) == U_OK) {

printf("Start framework on port %d\n", instance.port);

// Wait for the user to press on the console to quit the application

getchar();

} else {

fprintf(stderr, "Error starting framework\n");

}

printf("End framework\n");

ulfius_stop_framework(&instance);

ulfius_clean_instance(&instance);

return 0;

}

Installation

See INSTALL.md file for installation details

Documentation

See API.md file for API documentation details

Example programs source code

Example programs are available to under

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值