Browse Source

Adding /api and /apis to API request callback

ech1560
Xose Pérez 6 years ago
parent
commit
7c0b9e669d
2 changed files with 20 additions and 4 deletions
  1. +14
    -3
      code/espurna/api.ino
  2. +6
    -1
      code/espurna/web.ino

+ 14
- 3
code/espurna/api.ino View File

@ -128,8 +128,21 @@ void _onRPC(AsyncWebServerRequest *request) {
bool _apiRequestCallback(AsyncWebServerRequest *request) {
// Not API request
String url = request->url();
// Main API entry point
if (url.equals("/api") || url.equals("/apis")) {
_onAPIs(request);
return true;
}
// Main RPC entry point
if (url.equals("/rpc")) {
_onRPC(request);
return true;
}
// Not API request
if (!url.startsWith("/api/")) return false;
for (unsigned char i=0; i < _apis.size(); i++) {
@ -198,8 +211,6 @@ void apiRegister(const char * key, api_get_callback_f getFn, api_put_callback_f
}
void apiSetup() {
webServer()->on("/apis", HTTP_GET, _onAPIs);
webServer()->on("/rpc", HTTP_GET, _onRPC);
wsOnSendRegister(_apiWebSocketOnSend);
wsOnReceiveRegister(_apiWebSocketOnReceive);
webRequestRegister(_apiRequestCallback);


+ 6
- 1
code/espurna/web.ino View File

@ -93,7 +93,9 @@ void _onGetConfig(AsyncWebServerRequest *request) {
response->printf("{\n\"app\": \"%s\"", APP_NAME);
response->printf(",\n\"version\": \"%s\"", APP_VERSION);
response->printf(",\n\"backup\": \"1\"");
response->printf(",\n\"timestamp\": \"%s\"", ntpDateTime().c_str());
#if NTP_SUPPORT
response->printf(",\n\"timestamp\": \"%s\"", ntpDateTime().c_str());
#endif
// Write the keys line by line (not sorted)
unsigned long count = settingsKeyCount();
@ -392,6 +394,8 @@ void webSetup() {
#if WEB_EMBEDDED
_server->on("/index.html", HTTP_GET, _onHome);
#endif
// Other entry points
_server->on("/reset", HTTP_GET, _onReset);
_server->on("/config", HTTP_GET, _onGetConfig);
_server->on("/config", HTTP_POST | HTTP_PUT, _onPostConfig, _onPostConfigData);
@ -418,6 +422,7 @@ void webSetup() {
#else
_server->begin();
#endif
DEBUG_MSG_P(PSTR("[WEBSERVER] Webserver running on port %u\n"), port);
}


Loading…
Cancel
Save