A
A
Alf1622015-08-27 08:27:53
Computer networks
Alf162, 2015-08-27 08:27:53

How to create a REST API in C++?

Hello.
You need to create an http server that will accept JSON as input. Tell me, what tool in c ++ is better to use for these purposes?

Answer the question

In order to leave comments, you need to log in

5 answer(s)
S
sitev_ru, 2015-08-27
@sitev_ru

I can advise our solution, even the site works on our web server sitev.ru
Sources here: github.com/sitev We will
consult on Skype or icq - write ...

S
Stanislav Makarov, 2015-08-27
@Nipheris

HTTP support (ASIO based), URI handling and other basic web stuff: cpp-netlib.org
JSON: www.codeproject.com/Articles/20027/JSON-Spirit-AC... . There are forks on github.com, many other libraries, but I personally like this one better.
The first lib is not yet a release version, but the API has already stabilized, everything works. More than good enough for a light server (tested on localhost), it can be done for many visitors if you put it behind nginx for security.
PS Sudden alternative: FastCGI ( https://savannah.nongnu.org/projects/fastcgipp/) + normal webserver.

S
Sergei Borisov, 2015-08-27
@risik

For the http server in C++, there is, for example, POCO. pocoproject.org
Not sure if there is JSON out of the box though.

A
AxisPod, 2015-08-27
@AxisPod

A fairly simple example of a server is in boost::asio (well, or without boost) and at the same time a candidate for C ++ 17. Then you can look towards libevent (there is an implementation of the http server), libev, libuv. On it it is possible to rivet very suitable server. But this requires exactly cycling HTTP support.
The above cpp-netlib implements work with the HTTP protocol, but it is very hard and very long to build, the more code you write, the longer you will have to sleep, this can be hours.
Again, the above POCO has a rather mediocre network operation, but if the load is not large, you can safely use it.
Again, there are a lot of lightweight HTTP servers, but the quality of the implementation must be checked.
You can take, for example, nginx or apache and rivet modules for them, but here it is already easy to lose all the efficiency of nginx if you run after data in the database. With apache it will be easier.
Well, I also found https://github.com/eidheim/Simple-Web-Server , at least a ready-made solution for boost::asio.

S
Sergey, 2015-09-03
@zenden2k

https://github.com/civetweb/civetweb
disadvantage - how many threads and connections

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question