{"id":19554115,"url":"https://github.com/berndporr/fastcgi_json_cpp_api","last_synced_at":"2025-10-11T08:34:56.575Z","repository":{"id":146167502,"uuid":"350652382","full_name":"berndporr/fastcgi_json_cpp_api","owner":"berndporr","description":"Header-only JSON event driven communication between jQuery and C++ via nginx","archived":false,"fork":false,"pushed_at":"2025-02-14T07:26:34.000Z","size":1112,"stargazers_count":3,"open_issues_count":0,"forks_count":5,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-26T21:33:54.370Z","etag":null,"topics":["cpp","fastcgi","jquery","json","nginx","real-time","realtime"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/berndporr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2021-03-23T09:28:34.000Z","updated_at":"2025-02-14T07:26:37.000Z","dependencies_parsed_at":"2025-04-26T21:42:15.842Z","dependency_job_id":null,"html_url":"https://github.com/berndporr/fastcgi_json_cpp_api","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/berndporr/fastcgi_json_cpp_api","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/berndporr%2Ffastcgi_json_cpp_api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/berndporr%2Ffastcgi_json_cpp_api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/berndporr%2Ffastcgi_json_cpp_api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/berndporr%2Ffastcgi_json_cpp_api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/berndporr","download_url":"https://codeload.github.com/berndporr/fastcgi_json_cpp_api/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/berndporr%2Ffastcgi_json_cpp_api/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279006610,"owners_count":26084148,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-11T02:00:06.511Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cpp","fastcgi","jquery","json","nginx","real-time","realtime"],"created_at":"2024-11-11T04:25:59.147Z","updated_at":"2025-10-11T08:34:56.543Z","avatar_url":"https://github.com/berndporr.png","language":"C++","readme":"# jQuery \u003c--\u003e C++ JSON communication\n\nC++ Header-only event driven communication between jQuery in a web-browser via the nginx web-server.\nThis can implement, for example, a RESTful API for fast sensor data transfer.\n\nThis was developed because of a lack of a lightweight jQuery to C++\ncommunication. It's a small helper which can easily be\nincluded in any C++ application which needs to talk to a web page\nwhere realtime data needs to be exchanged.\n\nWorks alongside PHP as nginx can serve both!\n\n![alt tag](dataflow.png)\n\n## Prerequisites\n\n```\napt-get install libfcgi-dev\napt-get install libjsoncpp-dev\napt-get install nginx-core\n```\n\n## Installation\n\nThis is a pure header based library. All the code is in `json_fastcgi_web_api.h`. Just type:\n```\ncmake .\nsudo make install json_fastcgi_web_api.h\n```\nto install the header in the system-wide include dir.\n\n## Howto\n\nThe only file you need is:\n```\njson_fastcgi_web_api.h\n```\n\nThe file `json_fastcgi_web_api.h` has extensive inline documentation. \nIts doxygen generated online documentation is here: \nhttps://berndporr.github.io/fastcgi_json_cpp_api/\n\n### Implement the GET callback (server -\u003e client)\n\nThis is the callback which sends JSON packets to the client (website, phone app, etc):\n\n```\n\tclass GETCallback {\n\tpublic:\n\t\t/**\n\t\t * Needs to return the JSON data sent to the web browser.\n\t\t **/\n\t\tvirtual std::string getJSONString() = 0;\n\t};\n```\nOverload `getJSONString()` and return JSON. The recommended way\nof generating JSON is with the [jsoncpp](https://github.com/open-source-parsers/jsoncpp)\nlibrary which is part of all major Linux distros.\n\n### Implement the POST callback (client -\u003e server, optional)\n\nThis handler receives the JSON from jQuery POST command from the\nwebsite for example when the user presses a button. Implement the callback:\n\n```\n\tclass POSTCallback {\n\tpublic:\n\t\t/**\n\t\t * Receives the data from the web browser in JSON format.\n\t\t **/\n\t\tvirtual void postString(std::string arg) = 0;\n\t};\n```\nOverload `postString(std::string arg)` with a function which decodes the received POST data.\n\n### Start the communication\n\nThe start method takes as arguments the GET callback, the POST callback\nand the path to the fastCGI socket:\n\n```\nJSONCGIHandler jsoncgihandler;\njsoncgihandler.start(GETCallback* argGetCallback,\n                     POSTCallback* argPostCallback = nullptr,\n\t\t     const char socketpath[] = \"/tmp/fastcgisocket\");\n```\n\n### Stop the communication\n\nJust call `jsoncgihandler.stop()` to shut down the communication.\n\n\n## Example code\n\nThe subdir `fake_sensor_demo` contains a `demo_sensor_server` which fakes a temperature sensor\nand its readings are plotted in a web browser. The nginx\nconfig file and the website are in the `website`\ndirectory.\n\n\n\nBernd Porr, mail@berndporr.me.uk\n\n## Dynamic DNS\nif you have no static IP address you can use the the \"afraid\" dynamic DNS service:\n[Free DNS](http://freedns.afraid.org/)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fberndporr%2Ffastcgi_json_cpp_api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fberndporr%2Ffastcgi_json_cpp_api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fberndporr%2Ffastcgi_json_cpp_api/lists"}