{"id":14982649,"url":"https://github.com/kicer86/cpp_restapi","last_synced_at":"2025-03-17T16:13:05.693Z","repository":{"id":37044381,"uuid":"311400857","full_name":"Kicer86/cpp_restapi","owner":"Kicer86","description":"Rest API library for c++","archived":false,"fork":false,"pushed_at":"2025-03-04T15:19:04.000Z","size":659,"stargazers_count":46,"open_issues_count":0,"forks_count":10,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-17T16:13:00.442Z","etag":null,"topics":["cpp","github-api","libcurl","qt5","qt6","rest-api","restapi"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Kicer86.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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}},"created_at":"2020-11-09T16:37:07.000Z","updated_at":"2025-03-04T15:18:51.000Z","dependencies_parsed_at":"2024-01-01T11:24:01.965Z","dependency_job_id":"81b239f7-8abf-495a-bdf5-b923ea8c9fa1","html_url":"https://github.com/Kicer86/cpp_restapi","commit_stats":{"total_commits":219,"total_committers":7,"mean_commits":"31.285714285714285","dds":0.1278538812785388,"last_synced_commit":"1e265edcd525147b987eafed2f23970a8d8a5c08"},"previous_names":["kicer86/cpp_restapi","kicer86/github_api"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kicer86%2Fcpp_restapi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kicer86%2Fcpp_restapi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kicer86%2Fcpp_restapi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kicer86%2Fcpp_restapi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Kicer86","download_url":"https://codeload.github.com/Kicer86/cpp_restapi/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244066189,"owners_count":20392406,"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","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","github-api","libcurl","qt5","qt6","rest-api","restapi"],"created_at":"2024-09-24T14:05:48.398Z","updated_at":"2025-03-17T16:13:05.687Z","avatar_url":"https://github.com/Kicer86.png","language":"C++","readme":"\n# Rest API for c++\n\nThis is a c++ library originally written for accessing GitHub REST API v3.\nCurrently reorganized to be easily used with any Rest API available.\n\nIt supports three backends for establishing connections with remote API servers:\nQt6/5, Curl and cpp-httplib.\n\n# Submodules\nThis repository comes with submodules which are not necessary to build and use this project.\u003cbr\u003e\n\nAs of now the only submodule is `vcpkg` which can simplify build by providing required dependencies.\u003cbr\u003e\nPlease mind that vcpkg uses **telemetry**.\u003cbr\u003e\nVisit https://learn.microsoft.com/vcpkg/about/privacy for more details.\n\n## How to use it\n\nThis is a CMake based project and is meant to be included as a subproject.\n\nSimply embed cpp_restapi's sources in your project,\nchoose which http backend you prefer (all can be used simoultanously) and include `cpp_restapi` project in your `CMakeLists.txt` like this:\n\n```cmake\nset(CppRestAPI_QtBackend ON)         # use this line if you prefer Qt backend\nset(CppRestAPI_CurlBackend ON)       # use this line if you prefer Curl backend\nset(CppRestAPI_CppHttplibBackend ON) # use this line if you prefer cpp-httplib backend\nadd_subdirectory(cpp_restapi)\n```\n\nThen you can link your application against cpp_restapi:\n\n```cmake\ntarget_link_libraries(app\n    PRIVATE\n        cpp_restapi\n)\n```\n\nand that's all.\n\n##### Note:\nDepending on your choice of backend you may need to install libcurl, Qt and/or cpp-httplib libraries.\n\nQt backend can be compiled with Qt6 (default) or Qt5.\nIf no Qt6 is found, an automatic fallback to Qt5 will happen.\n\nSet `CppRestAPI_UseQt5` CMake variable to `TRUE` to force Qt5 usage (in case both versions are available).\n\n##### Standalone build:\nIt is possible to build this project as any other regular CMake project by invoking:\n```bash\ncmake -B build\ncmake --build build\n```\n\nIt can be usefull if you want to play with examples from `examples` dir or to run unit tests.\n\n## Examples\n\n## Simplest usage\n\n```c++\n#include \u003ciostream\u003e\n\n#include \u003ccpp_restapi/curl_connection.hpp\u003e\n\n\nint main(int argc, char** argv)\n{\n    // Access The Star Wars API\n    cpp_restapi::CurlBackend::Connection connection(\"https://swapi.dev/api\", {});\n\n    std::cout \u003c\u003c connection.get(\"people/1\") \u003c\u003c '\\n';\n    std::cout \u003c\u003c connection.get(\"starships/12/\") \u003c\u003c '\\n';\n\n    return 0;\n}\n```\n\nThis example accesses The Star Wars API using curl backend.\u003cbr\u003e\nAs you can see it is enought to instantiate `cpp_restapi::CurlBackend::Connection` object providing API url and after that request can be made.\n\nQt version:\n```c++\n#include \u003ciostream\u003e\n#include \u003cQCoreApplication\u003e\n#include \u003cQNetworkAccessManager\u003e\n\n#include \u003ccpp_restapi/curl_connection.hpp\u003e\n\n\nint main(int argc, char** argv)\n{\n    QCoreApplication qapp(argc, argv);\n    QNetworkAccessManager manager;\n\n    // Access The Star Wars API\n    cpp_restapi::QtBackend::Connection connection(manager, \"https://swapi.dev/api\", {});\n\n    std::cout \u003c\u003c connection.get(\"people/1\") \u003c\u003c '\\n';\n    std::cout \u003c\u003c connection.get(\"starships/12/\") \u003c\u003c '\\n';\n\n    return 0;\n}\n```\n\ncpp-httplib version:\n```c++\n#include \u003ciostream\u003e\n\n#include \u003ccpp_restapi/cpp-httplib_connection.hpp\u003e\n\n\nint main(int argc, char** argv)\n{\n    // Access The Star Wars API\n    cpp_restapi::CppHttplibBackend::Connection connection(\"https://swapi.dev/api\", {});\n\n    std::cout \u003c\u003c connection.get(\"people/1\") \u003c\u003c '\\n';\n    std::cout \u003c\u003c connection.get(\"starships/12/\") \u003c\u003c '\\n';\n\n    return 0;\n}\n```\n\n### Dedicated GitHub helpers\n\nFor accessing GitHub API it is possible to use exactly the same apporach as presented above.\u003cbr\u003e\nHowever, for conveniance, there are also additional helpers available:\n\n#### Qt example\n\n```c++\n#include \u003cQCoreApplication\u003e\n#include \u003cQDebug\u003e\n#include \u003cQNetworkAccessManager\u003e\n\n#include \u003ccpp_restapi/qt_connection.hpp\u003e\n#include \u003ccpp_restapi/github/connection_builder.hpp\u003e\n#include \u003ccpp_restapi/github/request.hpp\u003e\n\n\nint main(int argc, char** argv)\n{\n    QCoreApplication qapp(argc, argv);\n    QNetworkAccessManager manager;\n\n    auto connection = cpp_restapi::GitHub::ConnectionBuilder().build\u003ccpp_restapi::QtBackend::Connection\u003e(manager);\n    cpp_restapi::GitHub::Request request(connection);\n\n    qInfo() \u003c\u003c request.getRateLimit().c_str();\n    qInfo() \u003c\u003c request.getUserInfo(\"Kicer86\").c_str();\n\n    return 0;\n}\n```\n\nHere connection is being build with `ConnectionBuilder`.\u003cbr\u003e\nBuilder provides methods for setting additional connection parameters (passed as a second argument to `Connection` after API url).\u003cbr\u003e\nIt also sets the API url automatically.\u003cbr\u003e\nRefer documentation of `ConnectionBuilder` for more details.\n\nAdditionaly there is also `cpp_restapi::GitHub::Request` class available which comes with accessors to most common API requests.\n\n#### libcurl example\n\n```c++\n#include \u003ciostream\u003e\n\n#include \u003ccpp_restapi/curl_connection.hpp\u003e\n#include \u003ccpp_restapi/github/connection_builder.hpp\u003e\n#include \u003ccpp_restapi/github/request.hpp\u003e\n\n\nint main(int argc, char** argv)\n{\n    auto connection = cpp_restapi::GitHub::ConnectionBuilder().build\u003ccpp_restapi::CurlBackend::Connection\u003e();\n    cpp_restapi::GitHub::Request request(connection);\n\n    std::cout \u003c\u003c request.getRateLimit() \u003c\u003c '\\n';\n    std::cout \u003c\u003c request.getUserInfo(\"Kicer86\") \u003c\u003c '\\n';\n\n    return 0;\n}\n```\n\n#### cpp-httplib example:\n```c++\n#include \u003ciostream\u003e\n\n#include \u003ccpp_restapi/cpp-httplib_connection.hpp\u003e\n#include \u003ccpp_restapi/github/connection_builder.hpp\u003e\n#include \u003ccpp_restapi/github/request.hpp\u003e\n\n\nint main(int argc, char** argv)\n{\n    auto connection = cpp_restapi::GitHub::ConnectionBuilder().build\u003ccpp_restapi::CppHttplibBackend::Connection\u003e();\n    cpp_restapi::GitHub::Request request(connection);\n\n    std::cout \u003c\u003c request.getRateLimit() \u003c\u003c '\\n';\n    std::cout \u003c\u003c request.getUserInfo(\"Kicer86\") \u003c\u003c '\\n';\n\n    return 0;\n}\n```\n\nAlso please look into 'examples' directory for details.\n\n## Building examples\nExamples are located in the 'examples' directory of the project. \nTo build them set `CppRestAPI_Examples` CMake variable to `ON`.\nIt can be done when invoking `cmake` command by providing `-DCppRestAPI_Examples=ON` commanline argument (see `Standalone build` section).\nOr by modifying entry `CppRestAPI_Examples` in CMakeCache.txt file located in build directory of an already configured project.\n\nPlease mind that setting `CppRestAPI_Examples` to `ON` will force all backends to be used.\n\n## Building unit tests\nUnit tests are located in 'tests' directory of the project.\nTo build them set `CppRestAPI_Tests` CMake variable to `ON`.\n\nPlease mind that setting `CppRestAPI_Tests` to `ON` will force all backends to be used.\n\n## Links\n\nCode documentation available at https://kicer86.github.io/cpp_restapi/index.html\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkicer86%2Fcpp_restapi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkicer86%2Fcpp_restapi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkicer86%2Fcpp_restapi/lists"}