-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Darshan Sen <raisinten@gmail.com>
- Loading branch information
Showing
7 changed files
with
90 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
add_test(NAME packaging.project_configure COMMAND | ||
"${CMAKE_COMMAND}" | ||
-S "${CMAKE_CURRENT_SOURCE_DIR}/project" | ||
-B "${CMAKE_CURRENT_BINARY_DIR}/project" | ||
"-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}") | ||
|
||
add_test(NAME packaging.project_build COMMAND | ||
"${CMAKE_COMMAND}" | ||
--build "${CMAKE_CURRENT_BINARY_DIR}/project") | ||
|
||
set_tests_properties(packaging.project_build | ||
PROPERTIES DEPENDS packaging.project_configure) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
cmake_minimum_required(VERSION 3.18) | ||
project(project VERSION 0.0.1 LANGUAGES CXX DESCRIPTION "Project") | ||
|
||
set(CMAKE_CXX_STANDARD 20) | ||
|
||
add_subdirectory( | ||
"${PROJECT_SOURCE_DIR}/../../.." | ||
"${CMAKE_CURRENT_BINARY_DIR}/benoni_build") | ||
|
||
add_executable(project project.cc) | ||
target_link_libraries(project PRIVATE benoni) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#include <benoni/http.h> | ||
|
||
#if defined(__APPLE__) | ||
#include <CoreFoundation/CoreFoundation.h> | ||
#elif defined(linux) | ||
#include <glib.h> | ||
#endif | ||
|
||
#include <iostream> | ||
#include <variant> | ||
|
||
using benoni::Method; | ||
using benoni::request; | ||
using benoni::RequestOptions; | ||
using benoni::RequestOptionsBuilder; | ||
using benoni::Response; | ||
|
||
int main() { | ||
#if defined(linux) | ||
GMainLoop *loop = g_main_loop_new(nullptr, FALSE); | ||
#endif | ||
|
||
std::string url{"https://postman-echo.com/get"}; | ||
std::cout << "sending request to: \"" << url << "\"" << std::endl; | ||
|
||
request(std::move(url), RequestOptionsBuilder{}.build(), | ||
[](std::variant<std::string, Response> result) { | ||
// This callback is run in a background thread on Windows and Apple | ||
// and on the main thread on Gtk Linux. | ||
if (std::holds_alternative<std::string>(result)) { | ||
std::cerr << "error: [" << std::get<std::string>(result) << "]" | ||
<< std::endl; | ||
exit(EXIT_FAILURE); | ||
} | ||
|
||
Response response{std::get<Response>(result)}; | ||
|
||
std::cout << "response status: " << response.status << std::endl; | ||
std::cout << "response headers: [" << std::endl; | ||
for (const auto &[key, value] : response.headers) { | ||
std::cout << " \"" << key << "\": \"" << value << "\"," | ||
<< std::endl; | ||
} | ||
std::cout << "]" << std::endl; | ||
std::cout << "response body: \"" << response.body << "\"" | ||
<< std::endl; | ||
exit(EXIT_SUCCESS); | ||
}); | ||
|
||
#if defined(__APPLE__) | ||
CFRunLoopRun(); | ||
#elif defined(linux) | ||
g_main_loop_run(loop); | ||
g_main_loop_unref(loop); | ||
#else | ||
while (true) | ||
; | ||
#endif | ||
|
||
return 0; | ||
} |
File renamed without changes.
File renamed without changes.