Very simple HTTPS interface built atop libcurl. It's based off a few examples in libcurl's docs.
Highlights:
- HTTPS 1.2 enabled
- Always get a
struct
with response: https code; curl code; and body
vcpkg
is an open-source cross-platform library package management system from Microsoft; targeting macOS, Linux, and Windows.
It's very popular, and has strong CMake integration. Henceforth, it is chosen for this project as an example of third-party library integration.
Install vcpkg, configure it with your system. Then run:
[root]/vcpkg/vcpkg install curl
Or do the same with your system package manager, conan
, or whatever else you use.
$ mkdir 'cmake-build-debug' && cd "$_"
$ cmake -DCMAKE_TOOLCHAIN_FILE='[root]/vcpkg/scripts/buildsystems/vcpkg.cmake' \
-DCMAKE_BUILD_TYPE='Debug' \
..
$ cmake --build .
If you want to change the CLI options, note that they are generated with docopt
, use python -m pip install docopt-c
then:
$ python -m docopt_c ".docopt" -o "libcurl-simple-https/curl_simple_https/cli"
#include <stdlib.h>
#include <stdio.h>
#include <curl/curl.h>
#include <curl_simple_https.h>
#define CLIENT_ID "foo"
#define CLIENT_SECRET "bar"
int main(void) {
CURLU *urlp = curl_url();
CURLUcode rc = curl_url_set(urlp, CURLUPART_SCHEME, "https", 0);
rc = curl_url_set(urlp, CURLUPART_HOST, "oauth2.googleapis.com", 0);
rc = curl_url_set(urlp, CURLUPART_PATH, "/token", 0);
rc = curl_url_set(urlp, CURLUPART_QUERY, "grant_type=authorization_code", 0);
rc = curl_url_set(urlp, CURLUPART_QUERY, "client_id=" CLIENT_ID, CURLU_APPENDQUERY);
rc = curl_url_set(urlp, CURLUPART_QUERY, "client_secret=" CLIENT_SECRET, CURLU_APPENDQUERY);
if(rc != CURLUE_OK) return EXIT_FAILURE;
struct ServerResponse response = https_post(&urlp, /* extra headers */ NULL);
curl_url_cleanup(urlp);
if (response.code == CURLE_OK) {
printf("status_code: %l\n# response\n%s", response.code, response.body);
return EXIT_SUCCESS;
} else {
fprintf(stderr, "curl error: %s\n", curl_easy_strerror(res));
return EXIT_SUCCESS;
}
}
- CTest
- CPack
- More docs
- Headers support (input & output)
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or https://opensource.org/licenses/MIT)
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.