otakugifs.c 1.0.0
A simple, lightweight c wrapper the otakugifs.xyz API
otakugifs.c

A simple, lightweight c wrapper the otakugifs.xyz API compliant with C99.

Join the official Discord server here.

Requirements

  • libcurl (tested with 8.7.1-6)
  • cjson (tested with 1.7.17-1)

Installation

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

#define OTAKUGIFS_IMPL
#include "otakugifs.h"
This file contains structs and functions for interacting with the otakugifs.xyz API.

Documentation

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

Example

#define OTAKUGIFS_IMPL
#include <otakugifs.h>
#include <stdio.h>
#include <stdlib.h>
int main() {
// fetch gif
otaku_result result;
otaku_reaction(&result, "kiss", OTAKU_GIF); // use otaku_reactions() to get all available reactions
// download gif
otaku_http_response http_response;
otaku_download(&http_response, result.url);
// save image to file
FILE *file = fopen("kiss.gif", "wb");
fwrite(http_response.text, 1, http_response.len, file);
fclose(file);
// cleanup
otaku_free_http_response(&http_response);
return EXIT_SUCCESS;
}
@ OTAKU_GIF
Indicates that the response image is a gif.
Definition otakugifs.h:30
void otaku_free_http_response(const otaku_http_response *http_response)
Free an http response.
otaku_status otaku_reaction(otaku_result *result, const char *reaction, otaku_format format)
Fetch a reaction.
void otaku_free_result(const otaku_result *result)
Free a result.
otaku_status otaku_download(otaku_http_response *http_response, const char *url)
Download an image.
Struct for an http response.
Definition otakugifs.h:50
char * text
[out] Non-nullterminated text of the response.
Definition otakugifs.h:51
size_t len
[out] Length of the response text.
Definition otakugifs.h:52
Struct for a result.
Definition otakugifs.h:42
char * url
[out] URL to the result.
Definition otakugifs.h:44

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

For more examples, see tests/.