restinio - header-only http and websocket server
TRANSCRIPT
![Page 2: Restinio - header-only http and websocket server](https://reader031.vdocuments.us/reader031/viewer/2022012319/5a65157a7f8b9aa2548b6c4b/html5/thumbnails/2.jpg)
What is it?
● RESTinio is a header-only library for writing http-server in C++
● Based on asio
○ stand alone
○ master branch of https://github.com/chriskohlhoff/asio (close to Network
TS)
● Basic websocket support
● Currently it is in beta state
● BSD-3-CLAUSE license
2
![Page 3: Restinio - header-only http and websocket server](https://reader031.vdocuments.us/reader031/viewer/2022012319/5a65157a7f8b9aa2548b6c4b/html5/thumbnails/3.jpg)
Why creating yet another library of that kind?
● Lots of libs for implementing http-server
in C++
● Boost::Beast
● NIH syndrom?
3
![Page 4: Restinio - header-only http and websocket server](https://reader031.vdocuments.us/reader031/viewer/2022012319/5a65157a7f8b9aa2548b6c4b/html5/thumbnails/4.jpg)
Why creating yet another library of that kind?
● Lots of libs for implementing http-server
in C++
● Boost::Beast
● NIH syndrom?
4
● We tried lots of them
● Async handling is rare
● Control over execution context
● A bit of introspection
● Routing
Well, not too much options...
![Page 5: Restinio - header-only http and websocket server](https://reader031.vdocuments.us/reader031/viewer/2022012319/5a65157a7f8b9aa2548b6c4b/html5/thumbnails/5.jpg)
Hello world
#include <iostream>#include <restinio/all.hpp>
int main(){ restinio::run( restinio::on_this_thread() .port(8080) .address("localhost") .request_handler([](auto req) { return req->create_response().set_body("Hello, World!").done(); }));
return 0;}
5
![Page 6: Restinio - header-only http and websocket server](https://reader031.vdocuments.us/reader031/viewer/2022012319/5a65157a7f8b9aa2548b6c4b/html5/thumbnails/6.jpg)
Request handler
restinio::request_handling_status_t handler(restinio::request_handle_t req){ if( restinio::http_method_get() == req->header().method() && req->header().request_target() == "/" ) { req->create_response() .append_header( restinio::http_field::server, "RESTinio hello world server" ) .append_header_date_field() .append_header( restinio::http_field::content_type, "text/plain; charset=utf-8" ) .set_body( "Hello world!" ) .done(); return restinio::request_accepted(); } return restinio::request_rejected();}
6
![Page 7: Restinio - header-only http and websocket server](https://reader031.vdocuments.us/reader031/viewer/2022012319/5a65157a7f8b9aa2548b6c4b/html5/thumbnails/7.jpg)
RESTinio
● Async request handling
● http pipelining
● timeout control
● expressjs-like router
● response builders
● TLS support
● basic websocket support
● And more here: https://bitbucket.org/sobjectizerteam/restinio-0.3
7