55// #include <ESP8266WiFi.h>
66// #include <ESP8266HTTPClient.h>
77// #include <BearSSLHelpers.h>
8- #include < ArduinoJson.h>
98
109#if defined(ESP8266)
1110#include < ESP8266HTTPClient.h>
@@ -32,6 +31,12 @@ PocketbaseArduino::PocketbaseArduino(const char *baseUrl)
3231 fields_param = " " ;
3332}
3433
34+ PocketbaseArduino &PocketbaseArduino::collection (const char *collection)
35+ {
36+ current_endpoint = " collections/" + String (collection) + " /" ;
37+ return *this ;
38+ }
39+
3540String performGETRequest (const char *endpoint)
3641{
3742
@@ -218,7 +223,7 @@ String performDELETERequest(const char *endpoint)
218223#endif
219224}
220225
221- String performPOSTRequest (const char *endpoint, const std::unordered_map< String, String> ¶ms )
226+ String performPOSTRequest (const char *endpoint, const String &requestBody )
222227{
223228#if defined(ESP32)
224229 // ESP32 implementation
@@ -235,18 +240,6 @@ String performPOSTRequest(const char *endpoint, const std::unordered_map<String,
235240 {
236241 Serial.print (" [HTTPS] POST...\n " );
237242
238- // Create a JSON object to hold the parameters
239- DynamicJsonDocument jsonBody (1024 ); // Adjust the capacity based on your needs
240-
241- for (const auto ¶m : params)
242- {
243- jsonBody[param.first ] = param.second ;
244- }
245-
246- // Serialize the JSON object to a string
247- String requestBody;
248- serializeJson (jsonBody, requestBody);
249-
250243 int httpCode = http.POST (requestBody);
251244 if (httpCode > 0 )
252245 {
@@ -276,12 +269,6 @@ String performPOSTRequest(const char *endpoint, const std::unordered_map<String,
276269#endif
277270}
278271
279- PocketbaseArduino &PocketbaseArduino::collection (const char *collection)
280- {
281- current_endpoint = " collections/" + String (collection) + " /" ;
282- return *this ;
283- }
284-
285272String PocketbaseArduino::getOne (const char *recordId, const char *expand /* = nullptr */ , const char *fields /* = nullptr */ )
286273{
287274 String fullEndpoint = base_url + String (current_endpoint) + " records/" + recordId;
@@ -379,11 +366,11 @@ String PocketbaseArduino::deleteRecord(const char *recordId)
379366 return performDELETERequest (fullEndpoint.c_str ());
380367}
381368
382- String PocketbaseArduino::create (const std::unordered_map< String, String> ¶ms )
369+ String PocketbaseArduino::create (const String &requestBody )
383370{
384371 // Construct the endpoint based on the current_endpoint
385372 String fullEndpoint = current_endpoint + " records/" ;
386373
387374 // Call performPOSTRequest with the constructed endpoint and provided parameters
388- return performPOSTRequest (fullEndpoint.c_str (), params );
375+ return performPOSTRequest (fullEndpoint.c_str (), requestBody );
389376}
0 commit comments