nekos-best.c 1.0.0
A simple, lightweight c wrapper for nekos.best API
nekos-best.c

A simple, lightweight c wrapper for nekos.best API compliant with C99.

Join the official Discord server here.

Requirements

  • libcurl (tested with 8.6.0-3)
  • cjson (tested with 1.7.17-1)

Installation

Copy the single header file to source include directory and include the header. Specify NEKOSBEST_IMPL before including the header in the source file where you want to use the library.

#define NEKOSBEST_IMPL
#include "nekosbest.h"
This file contains structs and functions for interacting with the nekos.best API.

Documentation

Doxygen documentation is available here. (Jump to nekosbest.h)

Example

#define NEKOSBEST_IMPL
#include <nekosbest.h>
#include <stdio.h>
#include <stdlib.h>
int main() {
// manually create endpoint (use nekos_endpoints() to get all endpoints)
nekos_endpoint endpoint;
endpoint.name = "neko";
endpoint.format = NEKOS_PNG;
// fetch image
nekos_category(&results, &endpoint, 1);
// download first image
nekos_http_response http_response;
nekos_download(&http_response, results.responses[0].url);
// save image to file
FILE *file = fopen("neko.png", "wb");
fwrite(http_response.text, 1, http_response.len, file);
fclose(file);
// cleanup
nekos_free_results(&results, endpoint.format);
nekos_free_http_response(&http_response);
return EXIT_SUCCESS;
}
@ NEKOS_PNG
Indicates that the response image is a png and nekos_source_png should be used.
Definition nekosbest.h:38
nekos_status nekos_download(nekos_http_response *http_response, const char *url)
Download an image.
void nekos_free_http_response(const nekos_http_response *http_response)
Free an http response.
void nekos_free_results(const nekos_result_list *results)
Free a list of results.
nekos_status nekos_category(nekos_result_list *results, const nekos_endpoint *endpoint, int amount)
Get a list of images from a category.
Struct for an endpoint/category.
Definition nekosbest.h:43
char * name
[out] Name of the endpoint/category.
Definition nekosbest.h:44
nekos_format format
[out] Format of the endpoint/category.
Definition nekosbest.h:45
Struct for an http response.
Definition nekosbest.h:85
char * text
[out] Non-nullterminated text of the response.
Definition nekosbest.h:86
size_t len
[out] Length of the response text.
Definition nekosbest.h:87
Struct for a list of result images.
Definition nekosbest.h:77
nekos_result * responses
[out] Array of result images.
Definition nekosbest.h:78
char * url
[out] URL to the image.
Definition nekosbest.h:73

This example fetches an image from the 'neko' endpoint saves it to a file. Please note that this example does not handle errors.

For more examples, see tests/.