doompanning/demo/http_client
oxmox 7063e2102e Squashed 'external/nng/' content from commit 29b73962
git-subtree-dir: external/nng
git-subtree-split: 29b73962b939a6fbbf6ea8d5d7680bb06d0eeb99
2024-12-18 18:29:29 +01:00
..
CMakeLists.txt Squashed 'external/nng/' content from commit 29b73962 2024-12-18 18:29:29 +01:00
http_client.c Squashed 'external/nng/' content from commit 29b73962 2024-12-18 18:29:29 +01:00
README.adoc Squashed 'external/nng/' content from commit 29b73962 2024-12-18 18:29:29 +01:00

= http_client

This is a very simple HTTP client.  It only performs HTTP GET
operations, and does not follow HTTP redirects.  Think of it as
a trivialized version of cURL.  It is super simple, taking the
URL on the command line, and emitting the results to stdout.

For clarity, we are eliding TLS support.

It may not work on all systems, but it should work anywhere that
 both the standard C library and nng itself are available.

We check for errors, but no effort is made to clean up resources,
since this program just exits.  In longer running programs or libraries,
callers should take care to clean up things that they allocate.

Unfortunately many famous sites use redirects (usually to HTTPS
sites), so it's not a very useful replacement for cURL.

== Compiling

The following is an example typical of UNIX and similar systems like
Linux and macOS:

[source, bash]
----
% export CPPFLAGS="-I /usr/local/include"
% export LDFLAGS="-L /usr/local/lib -lnng"
% export CC="cc"
% ${CC} ${CPPFLAGS} http_client.c -o http_client ${LDFLAGS}
----

Alternatively, CMake can be used.  Here's an example if you have
Ninja build handy (highly recommended):

[source, bash]
----
% mkdir build
% cd build
% cmake -G Ninja  ..
% ninja
----

== Running

Make sure you specify the full URL (if the root page include
the simple "/".  The URL parser does not add it for you automatically.)

[source, bash]
----
% ./http_client http://httpbin.org/ip
----