π 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.
You can use this library directly with the Arduino IDE. It is distributed with
the name jcbhmr-fetch
.
- Download the latest source code
.zip
file from the [GitHub Releases] page. - Open your Arduino IDE. It doesn't need to be a specific project since Arduino IDE libraries are installed globally.
- Navigate to Sketch β‘οΈ Import Library β‘οΈ Manage Libraries on the top menu bar.
- Search for "fetch" in the search box.
- Install the one that is authored by @jcbhmr
- Profit! π
This project is also distributed on PlatformIO under the name jcbhmr-fetch
.
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.
xxxAsync
naming convention. You can learn more about our async
architecture on the docs site.
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!
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:
- Add badges to readme
- Re-work readme so that it flows better
- Use Doxygen to generate an HTML site
- Deploy the Doxygen content to GitHub Pages
- Add in-code references to the Fetch Standard
- Add Javadoc comments to the C++ source files
- Uses Arduino Lint & Arduino-CI
- Testing using AUnit in GitHub Actions
- A developer-focused wiki detailing the how & why
- A C++ formatter & linter
TODO: Add development short description