vttp
An HTTP backed Virtual Table extension for SQLite
Loading...
Searching...
No Matches
Functions
vapi.h File Reference

Yet Another Runtime TCP Stream internal functions API. More...

#include <stdio.h>
Include dependency graph for vapi.h:

Go to the source code of this file.

Functions

FILE * fetch (const char *url, const char *init[4])
 send() HTTP Request over a TCP socket, wrapping the response socket over the returned FILE * stream.
 

Detailed Description

Yet Another Runtime TCP Stream internal functions API.

Helper functions #vttp.c has available.

Function Documentation

◆ fetch()

FILE * fetch ( const char *  url,
const char *  init[4] 
)

send() HTTP Request over a TCP socket, wrapping the response socket over the returned FILE * stream.

Connects to host at URL over tcp and writes optional HTTP fields in INIT to the request. It returns a readable FILE stream that separates the frames by newlines, so you can read each logical frame one by one easier.

INIT slots are:

  • [0]: Method case insensitive
  • [1]: Headers
  • [2]: Body
  • [3]: plain int Body parser frame type.

INIT[3] is the only slot that fetch will read as a plain uint64.

Return values
NOT_0OK - Anything not 0 means the response stream was successfully opened.
NULLError - Check errno to learn about the error (too many to list here).

Typicode API Example

#define _GNU_SOURCE
#include <yapi.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void) {
FILE *stream = fetch("https://jsonplaceholder.typicode.com/todos", 0);
char *line = NULL;
size_t cap = 0;
while (getline(&line, &cap, stream) != -1) {
printf("%s", line);
}
free(line);
fclose(stream);
return 0;
}