Ways to implement a JSON RESTful service in C/C++

47,995

Solution 1

You might want to take a look at Casablanca introduced in Herb Sutter's blog.

Solution 2

there are a small number of libraries that support creating rest services with c, e.g. restinio:

#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;
}

Solution 3

try https://github.com/babelouest/ulfius great library to build C/C++ Restful APIs. can support all platforms: Linux, FreeBSD, Windows and others

Solution 4

Take a look at Oat++

It has:

  • URL routing with URL-parameters mapping
  • Support for Swagger-UI endpoint annotations.
  • Object-Mapping with JSON support.

Example endpoint:

ENDPOINT("GET", "users/{name}", getUserByName, PATH(String, name)) {
  auto userDto = UserDto::createShared();
  userDto->name = name;
  return createDtoResponse(Status::CODE_200, userDto);
}

Curl:

$ curl http://localhost:8000/users/john
{"name":"john"}

Solution 5

You could look at ffead-cpp. Apart from providing support for json and restfull web services it also includes more features. This framework may be too heavy weight for your situation though.

Share:
47,995
jllodra
Author by

jllodra

BY DAY: Entrepreneur, CEO, developer, etc. My office is at home. BY NIGHT: I think, read, code, enjoy, and I'm also a family man. FOR FUN: I love riding my bicycle, going out for dinner, and watching movies.

Updated on May 31, 2021

Comments

  • jllodra
    jllodra almost 3 years

    I am trying to do a JSON Restful web service in C/C++. I have tried Axis2/C and Staff, which work great for XML serialization/deserialization but not for JSON.