6 ms·
Nfhttp: A cross platform C++ HTTP library natively interfacing to platforms
- deleted 8y ago[deleted]
- Klonoar 8y agoI've been pointing out to people for some time now that Apple has docs (buried, of course, because it's Apple...) that outright indicate they do things behind the scenes with NSURLSession & co to make battery/radio management better. The effect of people dodging it in cross-platform frameworks has been something I've long wondered about.
- saagarjha 8y agoThis library seems to use platform APIs under the hood, so it might end up performing similarly.
- untog 8y agoI've long wondered about this, as well as the overhead of these cross-platform frameworks bundling an entire HTTP library (if they do? It's never easy to tell). Kudos to Kotlin Multiplatform, it seems that lets you use native APIs whenever you want.
- rapsey 8y agoIt mentions UWP support in readme, but that is wrong. WinHTTP C++ APIs are not present in UWP apps.
- deeringc 8y agoThis library seems to add a HTTP client impl built on top of NSURL, and another on top of CURL. It looks to me like everything else here is provided by Microsoft's CPPRestSDK - WinHTTP, UWP & Boost Asio based clients simply use the CppRestSDK impls under the hood.
- profquail 8y agoHow does this compare to cpprestsdk? https://github.com/Microsoft/cpprestsdk https://github.com/Microsoft/cpprestsdk
- speps 8y agoDependencies C++ REST SDK curl
- dasloop 8y agoThis is also my question. Having C ++ REST SDK as a dependency not only does not answer that but it adds additional questions. Also the duplicate use of libs (C ++ REST SDK already has JSON support).
- deeringc 8y agoThis interested me too so I looked through the source to find out. NFHTTP seems to add 2 clients of its own, one that uses NSURL (for Apple) and another that uses CURL (for Linux). Everything else (WinHTTP, UWP, and the fallback Boost Asio client) simply call down and use the cpprestsdk implementations directly. Seems like this library offers less itself than it says on the tin, given that 3/5 of its native impls just call down to cpprestsdk. It's a pity that spotify didn't simply add CURL and NSURL clients to cppressdk - that would have been far more useful IMO.
- bsenftner 8y agoFirst time I've seen JSON for Modern C++ https://nlohmann.github.io/json/ https://nlohmann.github.io/json/ Anyone have an use likes/dislikes?
- ddavis 8y agoIt's incredibly easy to use, I'm a fan.
- AndrewStephens 8y agoIts great
- deeringc 8y agoProbably one of the best C++ libraries out there. Can't recommend this highly enough.
- rhodysurf 8y agoIts awesome, Im a huge fan. dead simple to use
- bsenftner 8y agoFWIW, I use Restbed for this type of work. https://github.com/Corvusoft/restbed https://github.com/Corvusoft/restbed
- AndrewStephens 8y agoThis is a great idea. A lot of people are going to say "why not use libcurl like everyone else?". Curl is great but this project is a better idea for client-side code. libcurl is easy to integrate into C++ but hard to get right (this is not curl's fault). I see a lot of bad example code around the web that works(tm) but is not robust. I've seen so much bad curl code that I was moved to write[0] about some of the problems. libcurl doesn't use OS-level features. It doesn't pick up the users proxy settings or use the cache or cookie store. This is sometimes what you want but for standard client apps Nfhttp's approach is better. [0] https://sheep.horse/2019/3/using_libcurl_effectively_and_safely_in_c%2B%2B.html https://sheep.horse/2019/3/using_libcurl_effectively_and_saf...
- tele_ski 8y agoI agree, curl is great but the API is very difficult to use. Self plug, I've built my own curl c++ wrapper [0] for making thousands of requests per second (libuv event loop driver) and I find a cleaner API gets new devs into it a lot easier. It's definitely far from feature complete but I get a lot of mileage out of it. [0] https://github.com/jbaldwin/liblifthttp https://github.com/jbaldwin/liblifthttp
- deeringc 8y agoI agree in general that using native HTTP stacks is a good idea for all sorts of reasons, but it's worth calling out that NFHTTP is actually using CURL under the hood on Linux & Android platforms so this just ultimately wraps the CURL C API in a C++ API. On OSX it is using NSURL which is great, and on Windows it's using Microsoft's cpprestsdk library in order to talk with WinHTTP and UWP.
- adgasf 8y agoThis code is a great example of how awkward it is to glue CMake projects together.
- mises 8y agoWhat would you suggest instead? This is honest, not sarcastic. Cmake can be very powerful, and I don't know of a better option. For instance, it can even be set up to download the latest binary dependencies, which is very useful.
- adgasf 8y agoDownloading the latest binary dependencies is (IMO) not a good idea. You should download a known working version with a fixed hash. This will avoid unexpected version mismatches in production. When you want to upgrade, make it explicit. As for a better alternative, I would suggest Bazel or Buck.
- mises 8y agoI meant the latest I have pushed to a specific server I run. This means I can push up and everyone working on the project can fetch them easily. It requires intervention, and I wouldn't push until I've tested thoroughly and made necessary changes. I appreciate the recommendation, though it seems that bazel is heavily focused on java.
- adgasf 8y agoThat approach has a scaling problem because it requires the central server not to forget to verify the new version against all of the users. Instead, I think that upgrades should be decided on the user side. That is where the tests etc. live. Bazel is a multi-language system whose focus is actually on C++. This is because other languages have much simpler compilation models. I don't see why it would be a downside to have additional language support in your C++ build-system. For example, what happens when you want to do Android?
- geezerjay 8y agoHow does Nfhttp compare with POCO? https://pocoproject.org/ https://pocoproject.org/
- happyweasel 8y agoHow does this lib handle proxy settings? Does it provide an API to the current proxy settings on the supported platforms ? And an ability to use or not use the proxy per request?
- anon4242 8y agoHehe, seeing this I thought "Cool, this is exactly how Spotify handles separation between the GUI frontend and the backend in the Spotify app" and then I saw the organization name in the URL.. doh!
- benibela 8y agoI made such a library for FreePascal (http://benibela.de/sources_en.html#internettools http://benibela.de/sources_en.html#internettools) Windows WinINet, Android JNI for Apache HttpComponents or OkHttp, Linux OpenSSL through another FreePascal library