Skip to content

🌐 JavaScript's ezpz fetch() function for Arduino and friends

License

Notifications You must be signed in to change notification settings

web4more/fetch.ino

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

59 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🚧 Under construction πŸ‘·β€β™‚οΈ

fetch() for Arduino

🌐 JavaScript's ezpz fetch() function for Arduino and friends
πŸ”€ Forked from instanceofMA/arduino-fetch

πŸ”’ Supports SSL certificate verification
πŸ“š Uses ArduinoJson for .json()
πŸ”„ Supports async fetching
πŸ”° Easy to get started!

⬇️ See below for a comparison with instanceofMA/arduino-fetch. These projects may eventually merge.

Installation

Arduino PlatformIO

You can use this library directly with the Arduino IDE. It is distributed with the name jcbhmr-fetch.

  1. Download the latest source code .zip file from the [GitHub Releases] page.
  2. Open your Arduino IDE. It doesn't need to be a specific project since Arduino IDE libraries are installed globally.
  3. Navigate to Sketch ➑️ Import Library ➑️ Manage Libraries on the top menu bar.
  4. Search for "fetch" in the search box.
  5. Install the one that is authored by @jcbhmr
  6. Profit! πŸŽ‰

This project is also distributed on PlatformIO under the name jcbhmr-fetch.

Usage

Arduino Espressif

This project does not use C++ namespaces to scope code. Everything is available globally. This makes things easy for beginners! Just #include the library and call fetch() with your URL to get started.

⚠️ Synchronous execution is the default! All asynchronous functions are marked with the xxxAsync naming convention. You can learn more about our async architecture on the docs site.

Example

When you download this to an ESP32, this Sketch will fetch the example todo JSON and print out a little message for each todo. For more in-depth examples using async, headers, POST, etc. check out the docs site.

#include <jcbhmr-fetch.h>

void setup() {
  Serial.begin(9600);
  auto response = fetch("https://jsonplaceholder.typicode.com/todos");
  auto json = response.json();
  for (auto& todo : json) {
    auto completed = todo["completed"].as<bool>();
    auto title = todo["title"].as<String>();
    if (completed) {
      Serial.println("βœ… " + title);
    } else {
      Serial.println("❌ " + title);
    }
  }
  Serial.println("Push the RESET button to do it again!");
}

void loop() {
  delay(1000);
}

πŸ“š Check out the docs site for full API descriptions!

Comparison

This project's primary alternative is instanceofMA/arduino-fetch. We originally forked this repo in order to improve the documentation, testing, automation, etc. over the bare-bones structure of the original. These changes may be merged back into the original repo. Here's a (mostly) complete list of all the changes that this repo has made over instanceofMA/arduino-fetch:

  1. Add badges to readme
  2. Re-work readme so that it flows better
  3. Use Doxygen to generate an HTML site
  4. Deploy the Doxygen content to GitHub Pages
  5. Add in-code references to the Fetch Standard
  6. Add Javadoc comments to the C++ source files
  7. Uses Arduino Lint & Arduino-CI
  8. Testing using AUnit in GitHub Actions
  9. A developer-focused wiki detailing the how & why
  10. A C++ formatter & linter

Development

TODO: Add development short description

Releases

No releases published

Packages

No packages published

Languages

  • C++ 88.3%
  • WebIDL 10.7%
  • C 1.0%