diff --git a/Firebase.cpp b/Firebase.cpp index 6f41b2f2..40f8dfe1 100644 --- a/Firebase.cpp +++ b/Firebase.cpp @@ -28,11 +28,17 @@ Firebase& Firebase::auth(const String& auth) { } String Firebase::get(const String& path) { - return sendRequest("GET", path); + sendRequest("GET", path); + return readBody(); } String Firebase::push(const String& path, const String& value) { - return sendRequest("POST", path, value); + sendRequest("POST", path, value); + return readBody(); +} + +void Firebase::remove(const String& path) { + sendRequest("DELETE", path); } Firebase& Firebase::stream(const String& path) { @@ -74,15 +80,20 @@ String Firebase::makeURL(const String& path) { return url; } -String Firebase::sendRequest(const char* method, const String& path, const String& value) { - _error.reset(); +void Firebase::sendRequest(const char* method, const String& path, const String& value) { String url = makeURL(path); _http.begin(_host.c_str(), firebasePort, url.c_str(), true, firebaseFingerprint); - int statusCode = _http.sendRequest(method, (uint8_t*)value.c_str(), value.length()); + int statusCode = _http.sendRequest(method, (uint8_t*)value.c_str(), value.length()); + _error.reset(); if (statusCode < 0) { _error.set(statusCode, - String(method) + " " + url + ": " - + HTTPClient::errorToString(statusCode)); + String(method) + " " + url + ": " + + HTTPClient::errorToString(statusCode)); + } +} + +String Firebase::readBody() { + if (_error.code() != 0) { return ""; } // no _http.end() because of connection reuse. diff --git a/Firebase.h b/Firebase.h index b4104b56..ac7ff6ca 100644 --- a/Firebase.h +++ b/Firebase.h @@ -52,6 +52,7 @@ class Firebase { } String get(const String& path); String push(const String& path, const String& value); + void remove(const String& path); bool connected(); Firebase& stream(const String& path); bool available(); @@ -63,7 +64,9 @@ class Firebase { Event read(String& event); private: String makeURL(const String& path); - String sendRequest(const char* method, const String& path, const String& value = ""); + void sendRequest(const char* method, const String& path, const String& value = ""); + String readBody(); + HTTPClient _http; String _host; String _auth;