Skip to content

A bazel C++ HTTP TLS library built with boost and abseil.

License

Notifications You must be signed in to change notification settings

jimrogerz/ez-https

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

EZ-HTTPS

A bazel C++ HTTP TLS library built with boost and abseil.

Setup

Add the following to your WORKSPACE file:

load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")

git_repository(
    name = "ez-https",
    commit = "ed408505f8939b48da22363e7ae471f4e0c98d1e",
    remote = "https://github.com/jimrogerz/ez-https.git",
)

Add "@ez-https//:https" to your BUILD deps.

Usage

Example POST request to OpenAI:

#include "https.h"

Https https("api.openai.com");

auto status = https.Connect();
if (!status.ok()) {
  std::cerr << "Unable to connect: " << status << std::endl;
  return 1;
}

absl::string_view body = absl::StrFormat(
    "{"
    "\"prompt\": \"%s\","
    "\"n\": %d,"
    "\"size\": \"%s\","
    "\"response_format\": \"%s\""
    "}",
    prompt, num_images, size, image_count == 1 ? "b64_json" : "url");

auto response = https.SetPath("/v1/images/generations")
                     .SetContentType("application/json")
                     .SetAuthorization(absl::StrCat("Bearer ", kApiKey));
                     .Post(body);

https.Close();

if (!response.ok()) {
  std::cerr << "Unable to post request: " << response.status() << std::endl;
  return 1;
}

std::cout << response->body();

Contributing

Follow the Google C++ Style Guide. Update unit tests and confirm passing:

bazel test :https_test

Format the code:

clang-format -i *.cc *.h

About

A bazel C++ HTTP TLS library built with boost and abseil.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published