📜 ⬆️ ⬇️

Development of web applications in C ++


After reading a recent topic about using C ++ and fastcgi, I finally decided to publish my work on the subject of Web and C ++.

The existing solutions, from my point of view, implement simple things in a complex way. My goal was to eliminate this annoying misunderstanding by writing a library that allows you to write effective cross-platform web applications in C ++ as easily and quickly as in PHP, Python, Java, etc.

In order not to torment the reader with anticipation, let's go straight to the code of the simplest application written with the help of this library ( project page on Google Code , MIT license).

Source code Main.h
  1. #ifndef _MAIN_H
  2. #define _MAIN_H
  3.  
  4. #include <WebToolkit.h>
  5.  
  6. class HelloWorld:public IHttpRequestHandler
  7. {
  8. private:
  9.         Server server;
  10. public:
  11.         HelloWorld();
  12.         void Run();
  13.         void Handle(HttpRequest* request,HttpResponse* response);
  14. };
  15.  
  16. #endif

Main.cpp
  1. #include "Main.h"
  2.  
  3. HelloWorld::HelloWorld():server(8080,"0.0.0.0")
  4. {
  5.         server.RegisterHandler(this);
  6. }
  7.  
  8. void HelloWorld::Run()
  9. {
  10.         server.Run();
  11. }
  12.  
  13. void HelloWorld::Handle(HttpRequest* request,HttpResponse* response)
  14. {
  15.         response->Write("<html><body><h1>Hello, world!</h1></body></html>");
  16. }
  17.  
  18. int main()
  19. {
  20.         try
  21.         {
  22.                 HelloWorld app;
  23.                 app.Run();
  24.         }
  25.         catch(exception& e)
  26.         {
  27.                 cout<<e.what()<<endl;
  28.         }
  29. }

-. ( Windows — 29 ), . .

, Windows, Linux (, FreeBSD MacOS?). - embedded-. , ( , ASUS WL-500gP V1, OpenWRT).

- , , sqlite, , . , . — . , ++, , , -. :)

, — — ( ):

:

? ! :)

')

Source: https://habr.com/ru/post/61563/


All Articles