jart / cosmopolitan

build-once run-anywhere c library
ISC License
18.36k stars 630 forks source link

Example/how-to make a HTTP call #42

Closed sangupta closed 3 years ago

sangupta commented 3 years ago

I am a Java developer but been exploring C++/vlang/go as a hobby lately for cross platform CLI tools that increase my own productivity. Is there an example, or a plan to add Http call support to cosmopolitan, or a way I could use libcurl to achieve the same (In my limited knowledge, I believe libcurl is available for all platforms). Guidance on how to get it working will help.

I do see net module/package, as well as functions like recv to connect over network, but am looking for a higher-level construct/example.

Thanks.

jart commented 3 years ago

Cosmopolitan makes it possible to implement a 100 line of code HTTP curl command that works on all systems:

https://github.com/jart/cosmopolitan/blob/2c15efc249bafb84f401edd68eb862a098dd3699/examples/curl.c#L30-L107

Cosmopolitan provides all the low-level system primitives you need. It should be possible to build higher level libraries like libcurl and openssl on top of Cosmopolitan too. Feel free to file bug reports if you encounter issues which prevent that from happening. Anything else, I'll make your dreams come true if Adobe considers sponsoring this project. https://github.com/sponsors/jart

jart commented 3 years ago

Oh it's also worth mentioning that there's an HTTP server example using Cosmopolitan too! Check out redbean which can serve 1 million+ gzip encoded responses per second on a cheap personal computer. redbean makes it possible to share web applications that run offline as an single-file executable zip archive which contains your assets.

sangupta commented 3 years ago

@jart Thanks for the examples. I am loving my very limited play as I get to refresh coding in C.