Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to configure awtk-restful-httpd

2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "how to configure awtk-restful-httpd". In daily operation, I believe many people have doubts about how to configure awtk-restful-httpd. Xiaobian consulted all kinds of information and sorted out simple and easy operation methods. I hope to help you answer the doubts about "how to configure awtk-restful-httpd"! Next, please follow the small series to learn together!

1. introduced

In embedded applications, it is sometimes necessary to provide a WEB service for remote configuration and management of the system.

awtk-restful-httpd implements a RESTful HTTP services framework that helps developers quickly implement RESTful API-style WEB services. The main features are:

Small. About 3000 lines of code.

Simple. Register your own routing table processing function.

Easy to use. Built-in route parsing function, and provides an easy-to-use JSON reading and writing API.

Low memory overhead. Normal REST API memory requirements are less than 2K and static file memory requirements are less than 6K.

Easy to embed into AWTK applications. Seamless integration into AWTK's main loop, no additional threads required.

2 Preparation 2.1 Get awtk and compile git clone https://github.com/zlgopen/awtk.gitcd awtk; scons; cd -2.2 Get awtk-restful-httpd and compile git clone https://github.com/zlgopen/awtk-restful-httpd.gitcd awtk-restful-httpd

generate a resource

python ./ scripts/update_res.py all

Or generate resources through designer

Compile PC version

scons

Compile LINUX FB version

scons LINUX_FB=true

For full compilation options, see Compilation Options.

3. Run./ bin/demo4. Example 4.1 Defining routing tables static ret_t my_httpd_on_status(http_connection_t* c) { return RET_OK;}static ret_t my_httpd_on_element_action(http_connection_t* c) { return RET_OK;}static const http_route_t s_my_httpd_routes[] = { {HTTP_GET, "/status," my_httpd_on_status}, {HTTP_GET, "element/:action," my_httpd_on_element_action}};4.2 Static documents

Built-in static file processing, support for static file processing is quite easy.

static ret_t my_httpd_on_get_file(http_connection_t* c) { return http_route_handle_static_file(c, "static");}

"static" here means the directory where the static file is located.

Route matching rules are marked with an "*" for default routes and are placed at the end of the list to handle static files.

{HTTP_GET, "*", my_httpd_on_get_file}, 4.3 Static file transfer optimization

Some large files, especially text files, can be compressed and transmitted, which can greatly improve transmission efficiency. To avoid the memory and CPU overhead associated with runtime compression, you can precompress files and name them.gz files.

For example, when requesting static/js/awtk_asm.wasm file, if static/js/awtk_asm.wasm.gz exists, then return static/js/awtk_asm.wasm.gz to the client and set Content-Encoding, the browser will automatically decompress.

Content-Encoding: gzip4.4 Start Service ret_t my_httpd_start(httpd_t* httpd) { return_value_if_fail(httpd != NULL, RET_BAD_PARAMS); httpd_set_routes(httpd, s_my_httpd_routes, ARRAY_SIZE(s_my_httpd_routes)); return httpd_start(httpd);} At this point, the study of "awtk-restful-httpd how to configure" is over. I hope everyone's doubts can be solved. Theory and practice can better match to help everyone learn, go and try it! If you want to continue learning more relevant knowledge, please continue to pay attention to the website, Xiaobian will continue to strive to bring more practical articles for everyone!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report