Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/erkkah/naett
Tiny cross-platform HTTP / HTTPS client library in C.
https://github.com/erkkah/naett
android c cross-platform http http-client https ios linux macos portable tiny-library windows
Last synced: 7 days ago
JSON representation
Tiny cross-platform HTTP / HTTPS client library in C.
- Host: GitHub
- URL: https://github.com/erkkah/naett
- Owner: erkkah
- License: mit
- Created: 2021-11-09T17:36:59.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2024-04-13T18:52:23.000Z (7 months ago)
- Last Synced: 2024-10-16T08:41:19.776Z (22 days ago)
- Topics: android, c, cross-platform, http, http-client, https, ios, linux, macos, portable, tiny-library, windows
- Language: C
- Homepage:
- Size: 141 KB
- Stars: 96
- Watchers: 5
- Forks: 12
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# naett /nɛt:/
Tiny HTTP client library in C.
Wraps native HTTP client functionality on macOS, Windows, Linux, iOS and Android in a single, simple non-blocking API.
## Using `naett`
Get the `naett.c` and `naett.h` files and throw them into your project. Check out the [example](./example) for a basic `Makefile` - based setup.
The library needs to be initialized by a call to `naettInit()`. On Android, you need to provide a `JavaVM*` handle in the call to `naettInit()`.
On the other platforms, call with `NULL`.See `naett.h` for reference docs.
## Platform implementations
`naett` uses the following HTTP client libraries on each platform:
| Platform | Library / component | Build with |
| --- | --- | --- |
| macOS, iOS | NSURLRequest | -framework Foundation |
| Windows | WinHTTP Sessions | -lwinhttp |
| Android | java.net.URL | NDK |
| Linux | libcurl | -lcurl -lpthread |### Example
```C
#include "naett.h"
#include
#includeint main(int argc, char** argv) {
naettInit(NULL);naettReq* req =
naettRequest("https://foo.site.net", naettMethod("GET"), naettHeader("accept", "application/json"));naettRes* res = naettMake(req);
while (!naettComplete(res)) {
usleep(100 * 1000);
}if (naettGetStatus(res) < 0) {
printf("Request failed\n");
return 1;
}int bodyLength = 0;
const char* body = naettGetBody(res, &bodyLength);printf("Got %d bytes of type '%s':\n", bodyLength, naettGetHeader(res, "Content-Type"));
printf("%.100s\n...\n", body);
}
```