Rockets icon indicating copy to clipboard operation
Rockets copied to clipboard

REST and websockets C++ library

trafficstars

Rockets

A library for easy HTTP and websockets messaging in C++ applications.

Travis CI Language grade: C/C++

Table of Contents

  • Features
  • Build
  • Usage
  • Contribute
  • Funding & Acknowledgment
  • License

Features

Rockets provides the following features:

  • HTTP server with integrated websockets support
  • HTTP client for making simple asynchronous requests (with or without payload)
  • Websockets client for sending, broadcasting and receiving text and binary messages
  • Support for JSON-RPC as a communication protocol over HTTP and websockets. Rockets extends the 2.0 specification by providing support for Cancellation and Progress notifications of pending requests.
    • Server
    • C++ client
    • Javascript client
    • Python client
  • Event loop integration for Qt and libuv through the appropriate Server constructor

Build

Rockets is a cross-platform library designed to run on any modern operating system, including all Unix variants. It requires a C++11 compiler and uses CMake to create a platform specific build environment. The following platforms and build environments are tested:

  • Linux: Ubuntu 16.04, 18.04
  • Mac OS X: 10.9 - 10.14

Rockets requires the following external, pre-installed dependencies:

Building from source is as simple as:

git clone --recursive https://github.com/BlueBrain/Rockets.git
mkdir Rockets/build
cd Rockets/build
cmake -GNinja ..
ninja

Usage

Hello world REST server

#include <rockets/server.h>
#include <iostream>

int main(int , char** )
{
    rockets::Server server;
    std::cout << "Rockets REST server running on " << server.getURI() << std::endl;

    server.handle(rockets::http::Method::GET, "hello", [](auto) {
        return rockets::http::make_ready_response(rockets::http::Code::OK, "world");
    });
    for(;;)
        server.process(100);
    return 0;
}

Hello world websockets server

#include <rockets/server.h>
#include <iostream>

int main(int , char** )
{
    rockets::Server server("", "myws");
    std::cout << "Rockets websockets server running on " << server.getURI() << std::endl;

    server.handleText([](const auto& request) {
        return "server echo: " + request.message;
    });
    for(;;)
        server.process(100);
    return 0;
}

Production REST server example

For a more elaborate use of a Rockets REST server, check out the RestServer of Tide.

Production websockets server example

For a more elaborate use of a Rockets websockets server, check out the RocketsPlugin of Brayns.

Contribute

Follow the next guidelines when making a contribution:

  • Install our pre-commit hooks with pre-commit install prior the first commit
  • Use Conventional Commits spec whenever making a commit
  • Keep PRs to a single feature or fix

Funding & Acknowledgment

The development of this software was supported by funding to the Blue Brain Project, a research center of the École polytechnique fédérale de Lausanne (EPFL), from the Swiss government’s ETH Board of the Swiss Federal Institutes of Technology.

Copyright (c) 2021 Blue Brain Project/EPFL

License

Rockets is licensed under the LGPL version 3, unless noted otherwise, e.g., for external dependencies. See file LICENSE.txt for the full license. External dependencies are either LGPL or BSD-licensed. See file ACKNOWLEDGEMENTS.txt and AUTHORS.txt for further details.

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License version 3 as published by the Free Software Foundation.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA