Fetch for Arduino

fetch is a high level HTTP Request Library that gives you a javascript fetch like API.

ResponseOptions options;
options.method = "POST";
options.fingerprint = "DC 78 3C 09 3A 78 E3 A0 BA A9 C5 4F 7A A0 87 6F 89 01 71 4C";
options.headers.contentType = "application/json";
options.body = "{\"email\": \"[email protected]\", \"password\": \"test:80\"}";

/** In JSON, this would look like:
 * options = {
 *      method: "POST",
 *      fingerprint: "DC 78 3C 09 3A 78 E3 A0 BA A9 C5 4F 7A A0 87 6F 89 01 71 4C",
 *      headers: { contentType: "application/json" },
 *      body: "{\"email\": \"[email protected]\", \"password\": \"test:80\"}",
 * }
 */

Response response = fetch("https://api.grandeur.tech/auth/login/?apiKey=grandeurkywxmoy914080rxf9dh05n7e", options);

Include

#include <Fetch.h>

Usage

Response response = fetch(const char* url, RequestOptions options);

Request Options

RequestOptions options;

/**
    {
        method: "GET" || "POST" || "HEAD" || "PUT" || "DELETE",
        headers: { "Content-Type": "application/x-www-form-urlencoded", "Content-Length": Automatic, "Host: FromURL, "User-Agent": "arduino-fetch", "Cookie": "", "Accept": "* /*", "Connection": "close", "Transfer-Encoding": "chunked" },
        body: "",
        redirect: "follow" || "manual", "error",
        follow: Integer,

    }
*/

ResponseOptions options;
options.method = "POST";
options.body = "email=EMAIL&password=PASSWORD";

Request Body

String body;
// application/x-www-form-urlencoded
body = "email=EMAIL&password=PASSWORD";
// application/json
body = "{\"email\":\"EMAIL\", \"password\"=\"PASSWORD\"}";

Request Headers

Headers headers;

headers.contentType = "application/json";
headers.connection = "keep-alive";
headers.cookie = "abc=def,ghi=jkl"; // Not yet supported.

Response

Response response;

String data = response.text();
JSONBody data = response.json(); // Not yet supported.
const Blob = response.blob(); // Not yet supported.
const FormData = response.formData(); // Not yet supported.
unsigned int[] array = response.arrayBuffer(); // Not yet supported.

bool ok = response.ok;
int status = response.status;
const char* statusText = response.statusText;
bool redirected = response.redirected; // Not yet supported.
const char* type = response.type; // Not yet supported.
const char* response.headers.get("content-type");
Headers headers = response.headers.raw(); // Not yet supported
const char* contentTypeHeader = headers["content-type"]; // Not yet supported.

GitHub

View Github