Member-only story

Using Boost and Served Libraries to Build a C++ REST API Service

Petr Plavjaník

We will build a simple REST API service in C++ using Served library from scratch.

I have been developing REST APIs on different platforms and programming languages. The benefit of using C++ is high-performance, minimum dependencies, and smaller footprint. Today, we will be running the service on our computer. Later, we will see how to run it in a Docker container and deploy it to other platforms.

Served is a C++ library for building high-performance RESTful web servers. Served builds upon Boost.ASIO to provide a simple API for developers to create HTTP services in C++.

Boost is a set of libraries for the C++ programming language which provides support for tasks and structures such as linear algebra, pseudorandom number generation, multithreading, image processing, regular expressions, and unit testing. It contains over eighty individual libraries.

This tutorial provides a step by step instructions on how to build and debug such C++ program on Mac.

Photo by Max Nelson on Unsplash

1. Install Homebrew and CMake

Homebrew is a package for macOS.

Install it using the following command:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

You should get a following message at the end:

==> Installation successful!

The important bit is that it has installed XCode Command Line Tools using xcode-select --install command as part of the process. It provides the Clang C/C++ compiler.

We will be using CMake and pkg-config to build Served and our service and curl to interact with the service.

CMake is a cross-platform open-source software tool for managing the build process. It is used in conjunction with native build environments such as Make. It has minimal dependencies and it requires only a C++ compiler on its own build system.

pkg-config is a tool that defines and supports a unified interface for querying installed libraries for the purpose of compiling software that depends on them. It allows you to work without explicit knowledge of detailed library path…

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

No responses yet

Write a response