• This repository has been archived on 30/Jun/2021
  • Stars
    star
    709
  • Rank 63,849 (Top 2 %)
  • Language
    C++
  • License
    MIT License
  • Created about 10 years ago
  • Updated almost 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A C++11 RESTful web server library

Served

Served Logo

Build Status

Overview

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++.

Features:

  • HTTP 1.1 compatible request parser
  • Middleware / plug-ins
  • Flexible handler API
  • Cross-platform compatible

Installation

Requirements

Building

$ git clone [email protected]:meltwater/served.git
$ mkdir served.build && cd served.build
$ cmake ../served && make

Or, using bazel:

$ git clone [email protected]:meltwater/served.git
$ cd served
$ bazel build :served
$ bazel test :served-test

Getting Started

The most basic example of creating a server and handling a HTTP GET for the path /hello:

#include <served/served.hpp>

int main(int argc, char const* argv[]) {
	// Create a multiplexer for handling requests
	served::multiplexer mux;

	// GET /hello
	mux.handle("/hello")
		.get([](served::response & res, const served::request & req) {
			res << "Hello world!";
		});

	// Create the server and run with 10 handler threads.
	served::net::server server("127.0.0.1", "8080", mux);
	server.run(10);

	return (EXIT_SUCCESS);
}

To test the above example, you could run the following command from a terminal:

$ curl http://localhost:8080/hello -ivh

You can also use named path variables for REST parameters:

mux.handle("/users/{id}")
	.get([](served::response & res, const served::request & req) {
		res << "User: " << req.params["id"];
	});

To test the above example, you could run the following command from a terminal:

$ curl http://localhost:8080/users/dave -ivh

If you need to be more specific, you can specify a pattern to use to validate the parameter:

mux.handle("/users/{id:\\d+}")
	.get([](served::response & res, const served::request & req) {
		res << "id: " << req.params["id"];
	});

To test the above example, you could run the following command from a terminal:

$ curl http://localhost:8080/users/1 -ivh

Method handlers can have arbitrary complexity:

mux.handle("/users/{id:\\d+}/{property}/{value:[a-zA-Z]+")
	.get([](served::response & res, const served::request & req) {
		// handler logic
	});

If you want to automatically log requests, you could use a plugin (or make your own):

#include <served/plugins.hpp>
// ...
mux.use_after(served::plugin::access_log);

You can also access the other elements of the request, including headers and components of the URI:

mux.handle("/posts/{id:\\d+}")
	.post([](served::response & res, const served::request & req) {
		if (req.header("Content-Type") != "application/json") {
			served::response::stock_reply(400, res);
			return;
		}
		res << req.url().fragment();
	});

Compile Options

Option Purpose
SERVED_BUILD_SHARED Build shared library
SERVED_BUILD_STATIC Build static library
SERVED_BUILD_TESTS Build unit test suite
SERVED_BUILD_EXAMPLES Build bundled examples
SERVED_BUILD_DEB Build DEB package (note: you must also have dpkg installed)
SERVED_BUILD_RPM Build RPM package (note: you must also have rpmbuild installed)

System Compatibility

OS Compiler Status
Linux GCC 4.8 Working
OSX Clang 3.5 Working

TODO

  • Chunked encoding support

Contributing

Pull requests are welcome.

Authors

Copyright

See LICENSE.md document

More Repositories

1

docker-cleanup

DEPRECATED Automatic Docker image, container and volume cleanup
Shell
586
star
2

drone-cache

A Drone plugin for caching current workspace files between builds to reduce your build times
Go
335
star
3

gen_rmq

Elixir AMQP consumer and publisher behaviours
Elixir
183
star
4

drone-convert-pathschanged

Drone conversion extension to include/exclude pipelines and pipeline steps based on paths changed
Go
133
star
5

secretary

DEPRECATED Secrets management for dynamic environments
Go
94
star
6

terraform-aws-asg-dns-handler

Terraform module for dynamically setting hostnames following a pattern on instances in AWS Auto Scaling Groups
Python
75
star
7

rabbitio

RabbitIO is used to move data in and out of RabbitMQ
Go
70
star
8

elasticsearch-batch-percolator

(deprecated) High performance Elasticsearch percolator
Java
48
star
9

lighter

DEPRECATED Marathon deployment automation tool
Python
43
star
10

awsudo

A simple utility for executing cli commands with an assumed role.
JavaScript
41
star
11

docker-mesos

Mesos, Marathon and Chronos using Docker Compose
Shell
39
star
12

jugri

The JUpyter-GRemlin Interface
Python
35
star
13

rxrabbit

RabbitMQ Java client built on RxJava
Java
33
star
14

ex_lsh

A configurable implementation of locality-sensitive hashing in Elixir
Elixir
25
star
15

proxymatic

DEPRECATED Marathon service discovery proxy
Python
24
star
16

quitsies

A persisted drop-in replacement for Memcached, respecting the rules of quitsies.
C++
16
star
17

api-gateway-demo

Nginx application showcasing how to do lightweight tests with ruby rspec
Ruby
15
star
18

kotlin-compose

Docker-compose wrapper for the JVM
Kotlin
12
star
19

rabbit-puppy

Configures RabbitMQ server based on YAML configuration
Kotlin
7
star
20

docker-elasticsearch-aws

Elasticsearch Docker image with the Amazon EC2 plugin
7
star
21

MeltwaterEng-public-presentations

List of public talks by Meltwater Engineering: meetup presentations, recorded conference talks, slides.
7
star
22

tau

Functional time and date JavaScript library.
JavaScript
6
star
23

puppet-marathon

Puppet Module for Mesos Marathon
Ruby
6
star
24

puppet-cobbler

Fork of https://bitbucket.org/jsosic/puppet-cobbler
HTML
5
star
25

puppet-incron

Puppet module to provide an incron resource type
Ruby
4
star
26

sparkline

ANSI Sparklines for Elixir
Elixir
4
star
27

supervisor_health

Elixir
4
star
28

meltwater-elasticsearch-queries

Java
3
star
29

phi

Functional tools for JavaScript inspired by Ramda and Ramda Adjunct.
JavaScript
3
star
30

confex_config_provider

Confex runtime configuration provider for Distillery
Elixir
3
star
31

vagrant-coreos

Vagrant infrastructure for CoreOS on Amazon AWS
HTML
3
star
32

underthehood-blog-tests-examples

Examples for blog post "Using Selenium-Server on Docker to run your Browser Tests"
Ruby
3
star
33

mlabs-health

Health monitor for Node.js microservices.
JavaScript
3
star
34

makenew-koa-service

Bootstrap a new Node.js Koa microservice in five minutes or less.
Shell
2
star
35

esi-include-webpack-plugin

Webpack 4 plugin to inject an esi comment for prod OR fetch and do the injection in dev
JavaScript
2
star
36

mlabs-aws

Convenient wrappers around the AWS SDK to keep code DRY.
JavaScript
2
star
37

threaded-logstasher

DEPRECATED Threaded logstash handler and formatter in Python.
Python
2
star
38

makenew-node-lib

Bootstrap a new Node.js npm package in five minutes or less.
Shell
2
star
39

docker-foundation-terraform

Repo to use when building terraforming docker image
2
star
40

node-examplr

Example runner for Node.js packages.
JavaScript
2
star
41

mlabs-graphql

Node.js GraphQL client and server toolkit.
JavaScript
2
star
42

docker-aws-cli

Custom Docker build of the AWS CLI
Dockerfile
1
star
43

the-orchard

A CLI tool to generate the markup for including web dependencies
JavaScript
1
star
44

puppet-erlang

puppet module to install erlang from source
Puppet
1
star
45

puppet-python

Installation of python from source via puppet
Puppet
1
star
46

mlabs-http

Node.js HTTP client wrapper around Got
JavaScript
1
star
47

puppet-monit

HTML
1
star
48

puppet-newrelic_agent

Puppet Module for Installing & Managing the various NewRelic server monitoring agents
Puppet
1
star
49

docker-nginx-http-https-reverse-proxy

Nginx HTTP server which proxies an external SSL host
Dockerfile
1
star
50

pagerduty-campfire

Polls Pagerduty for new stuff, posts it to Campfire
1
star
51

meltwater-ruby

(deprecated) Ruby Client for the Meltwater API
Ruby
1
star
52

terraform-provider-meltwater

A Terraform provider for Meltwater based on the persistent/infrastructure parts of the Meltwater API. Such as setting up webhooks and recurring exports.
Go
1
star
53

puppet-es

Puppet module for Elastic Search as a Defined Type
HTML
1
star
54

mlabs-logger

Structured logging for Node.js services.
JavaScript
1
star
55

mlabs-koa

Koa middleware suite and server bootstrapper.
JavaScript
1
star
56

docker-awscli

Docker image of Amazon AWS Command Line Interface
Shell
1
star
57

meltwater-killercoda

Meltwater Engineering's Public / Shared Training Center
Shell
1
star
58

meltwater-php

(deprecated) PHP Client for the Meltwater API
PHP
1
star
59

.github

Meltwater's community health files
1
star