Skip to content

Client Documentation

hij1nx edited this page Oct 3, 2014 · 7 revisions

The following code examples assume you are using using namespace http; and using namespace std; for the sake of readability. The practice of using namespaces like this in your code is not recommended.

CONSTRUCTOR

You can construct a client by passing either a url or options struct. In either case, a callback is required which will yield an instance of the Response class.

URL

For simplicity, you can just pass a url in the form of a string to construct a client instance.

  Client client("http://google.com", [](auto& res) {
    cout << res.body << endl;
  })

  client.end();

OPTIONS

  Options opts;
  opts.host = "google.com";
  opts.port = 80;
  opts.url = "/";
  opts.method = "GET";

  Client client(opts, [](auto& res) {
    cout << res.body << endl;
  });

INSTANCE METHODS

client.write();

Write a buffer or string to the body of the request.

client.write([buffer|string]);

client.end();

Will finish writing the request.

client.end([buffer|string]);

INSTANCE MEMBERS

client.bytesRead

Tells you how many bytes have been read in the lifetime of the client instance.