restinio - header-only http and websocket server

8
RESTinio Nicolai Grodzitski

Upload: corehardby

Post on 22-Jan-2018

68 views

Category:

Technology


6 download

TRANSCRIPT

Page 1: Restinio - header-only http and websocket server

RESTinio

Nicolai Grodzitski

Page 2: Restinio - header-only http and websocket server

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

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

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

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

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

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

Page 8: Restinio - header-only http and websocket server

https://bitbucket.org/sobjectizerteam/restinio-0.3

Nicolai [email protected]