jllodra
jllodra

Reputation: 1478

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

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.

Upvotes: 34

Views: 67247

Answers (9)

david euler
david euler

Reputation: 824

For web service in C, you can leverage library like ulfius, civetweb:

https://github.com/babelouest/ulfius

https://github.com/civetweb/civetweb/blob/master/docs/Embedding.md

For web service in C++, you can leverage library like libhv, restbed:

https://github.com/ithewei/libhv

https://github.com/Corvusoft/restbed

Upvotes: 1

Adam Gu
Adam Gu

Reputation: 166

You may want to take a look at webcc.

It's a lightweight C++ HTTP client and server library for embedding purpose based on Boost.Asio (1.66+).

It's quite promising and actively being developed.

It includes a lot of examples to demonstrate how to create a server and client.

Upvotes: 2

lganzzzo
lganzzzo

Reputation: 698

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"}

Upvotes: 3

Shaaban Ebrahim
Shaaban Ebrahim

Reputation: 10422

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

Upvotes: 9

Rand0m
Rand0m

Reputation: 372

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

Upvotes: 7

georgeliatsos
georgeliatsos

Reputation: 1218

For C++ web service, I am using the following stack:

Upvotes: 3

Marija Radezova
Marija Radezova

Reputation: 11

There is a JIRA project resolved the support of JSON in AXIS2/C .
I implemented in my project and I managed with the writer (Badgerfish convention) but still I am trying to manage with the reader.
It seems more complicated managing with the stack in the memory.

Upvotes: 1

Philipp
Philipp

Reputation: 11833

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

Upvotes: 17

Rutix
Rutix

Reputation: 861

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.

Upvotes: 3

Related Questions