[GH-ISSUE #781] REST API instead of HTML Pages #653

Open
opened 2026-02-28 01:26:24 +03:00 by kerem · 19 comments
Owner

Originally created by @vip20 on GitHub (Dec 9, 2018).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/781

I want to create my own UI so changing this to REST API instead of a HTML page would be of a help

Originally created by @vip20 on GitHub (Dec 9, 2018). Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/781 I want to create my own UI so changing this to REST API instead of a HTML page would be of a help
Author
Owner

@ivanmonteiro commented on GitHub (Dec 10, 2018):

Also interested

<!-- gh-comment-id:446015404 --> @ivanmonteiro commented on GitHub (Dec 10, 2018): Also interested
Author
Owner

@bkrajendra commented on GitHub (Apr 20, 2019):

Any plans on this?
It will be very cool if all routes are available as rest api by default and there is way to disable front end UI. It will open lot of possibilities for UI. Also might reduce the memory footprint if UI is totally removed. I understand that basic intention of developer must have been making a standalone interface for wificonfig, but many things have changed now and there are ways we can better put UI on clientside with hybrid apps, native apps, PWA, or many other method.

i know all routes are available now also and we can definitely interface any front-end with it, but its not optimized the way it should be for API consumption.

@tzapu @vip20 @ivanmonteiro

<!-- gh-comment-id:485150044 --> @bkrajendra commented on GitHub (Apr 20, 2019): Any plans on this? It will be very cool if all routes are available as rest api by default and there is way to disable front end UI. It will open lot of possibilities for UI. Also might reduce the memory footprint if UI is totally removed. I understand that basic intention of developer must have been making a standalone interface for wificonfig, but many things have changed now and there are ways we can better put UI on clientside with hybrid apps, native apps, PWA, or many other method. i know all routes are available now also and we can definitely interface any front-end with it, but its not optimized the way it should be for API consumption. @tzapu @vip20 @ivanmonteiro
Author
Owner

@vip20 commented on GitHub (Apr 20, 2019):

@bkrajendra can you try this https://github.com/vip20/esp8266-wifimanager
Let me know if any issues. I have been using this with Nativescript. I dont know where I got this from, but I edited for my own usecase

<!-- gh-comment-id:485150350 --> @vip20 commented on GitHub (Apr 20, 2019): @bkrajendra can you try this https://github.com/vip20/esp8266-wifimanager Let me know if any issues. I have been using this with Nativescript. I dont know where I got this from, but I edited for my own usecase
Author
Owner

@bkrajendra commented on GitHub (Apr 20, 2019):

@vip20 i can try, but its always better to stick to original repo, as we can only get all updates in future from this repo. There are many available but its nice if API end points are available in original repo.!

I will look into the repo you provided and see if its helpful.

<!-- gh-comment-id:485150871 --> @bkrajendra commented on GitHub (Apr 20, 2019): @vip20 i can try, but its always better to stick to original repo, as we can only get all updates in future from this repo. There are many available but its nice if API end points are available in original repo.! I will look into the repo you provided and see if its helpful.
Author
Owner

@vip20 commented on GitHub (Apr 20, 2019):

@bkrajendra, I get it, but I couldn't wait longer as I had to carry on with my project

<!-- gh-comment-id:485151034 --> @vip20 commented on GitHub (Apr 20, 2019): @bkrajendra, I get it, but I couldn't wait longer as I had to carry on with my project
Author
Owner

@bkrajendra commented on GitHub (Apr 20, 2019):

yes.. im also waiting from long time, this feature is must. I was thinking of doing directly by sending POST/GET request from ionic app and handling html parsing at app side. this way @tzapu dont hve to change anything. but if little bit of HTML changed in WiFimanager it will break again. hence its better if simple JSON response is available from WM.

I dont if its possible or not in esp, but as im from web and mobile dev side, I know that on php server we can distinguish between ajax/rest client and browser through http headers. so its easy in server side to send selective response to client.
I'll have to look into how it can be done in esp.

<!-- gh-comment-id:485151919 --> @bkrajendra commented on GitHub (Apr 20, 2019): yes.. im also waiting from long time, this feature is must. I was thinking of doing directly by sending POST/GET request from ionic app and handling html parsing at app side. this way @tzapu dont hve to change anything. but if little bit of HTML changed in WiFimanager it will break again. hence its better if simple JSON response is available from WM. I dont if its possible or not in esp, but as im from web and mobile dev side, I know that on php server we can distinguish between ajax/rest client and browser through http headers. so its easy in server side to send selective response to client. I'll have to look into how it can be done in esp.
Author
Owner

@tablatronix commented on GitHub (Apr 20, 2019):

Please post a schema or routes suggesiton, development branch lets you add your own endpoints as webserver is public so it might be easy to hack into user code for now.

<!-- gh-comment-id:485159052 --> @tablatronix commented on GitHub (Apr 20, 2019): Please post a schema or routes suggesiton, development branch lets you add your own endpoints as webserver is public so it might be easy to hack into user code for now.
Author
Owner

@bkrajendra commented on GitHub (Apr 20, 2019):

Thanks @tablatronix for taking interest !
As i said i was looking for some ways to detect XHR and normal browser requests and I found this simple solution by detecting headers:

  if (server.hasHeader("X-Requested-With")) {
    Serial.print("Ajax Request Detected ");
    String xhr= server.header("X-Requested-With");
    Serial.println(xhr);
  // send JSON response 
  }else{
   // send HTML response
}

for this to work we need to have collectHeaders in setup before server.begin() :


  const char * headerkeys[] = {"User-Agent", "X-Requested-With"} ;
  size_t headerkeyssize = sizeof(headerkeys) / sizeof(char*);
  //ask server to track these headers
  server.collectHeaders(headerkeys, headerkeyssize);  
  server.begin();

Now we can send selective response to clients. If its browser then HTML response and if its a Android/ioS native client or a IONIC webview client then JSON response.
Also http clients can send this ("User-Agent", "X-Requested-With") header if they want to get JSON.

<!-- gh-comment-id:485164987 --> @bkrajendra commented on GitHub (Apr 20, 2019): Thanks @tablatronix for taking interest ! As i said i was looking for some ways to detect XHR and normal browser requests and I found this simple solution by detecting headers: ``` if (server.hasHeader("X-Requested-With")) { Serial.print("Ajax Request Detected "); String xhr= server.header("X-Requested-With"); Serial.println(xhr); // send JSON response }else{ // send HTML response } ``` for this to work we need to have collectHeaders in setup before server.begin() : ``` const char * headerkeys[] = {"User-Agent", "X-Requested-With"} ; size_t headerkeyssize = sizeof(headerkeys) / sizeof(char*); //ask server to track these headers server.collectHeaders(headerkeys, headerkeyssize); server.begin(); ``` Now we can send selective response to clients. If its browser then HTML response and if its a Android/ioS native client or a IONIC webview client then JSON response. Also http clients can send this ("User-Agent", "X-Requested-With") header if they want to get JSON.
Author
Owner

@vip20 commented on GitHub (Apr 20, 2019):

@bkrajendra can you please let me know where to add this?
I am not able to connect to wifi using 0.14 please let me know if you face the same issue

<!-- gh-comment-id:485165824 --> @vip20 commented on GitHub (Apr 20, 2019): @bkrajendra can you please let me know where to add this? I am not able to connect to wifi using 0.14 please let me know if you face the same issue
Author
Owner

@bkrajendra commented on GitHub (Apr 20, 2019):

@tablatronix
for API routes it can be something like:
GET api/v1/wifi
GET api/v1/wifinoscan
POST api/v1/wifisave
GET api/v1/info
GET api/v1/restart
GET api/v1/erase
GET api/v1/status

or better keep the routes same as now and use my previous solution to detect XHR/Browser. This will save lot of effort and avoid creating separate handlers. We can keep same handlers and just implement request detection.

<!-- gh-comment-id:485166375 --> @bkrajendra commented on GitHub (Apr 20, 2019): @tablatronix for API routes it can be something like: GET api/v1/wifi GET api/v1/wifinoscan POST api/v1/wifisave GET api/v1/info GET api/v1/restart GET api/v1/erase GET api/v1/status **or better keep the routes same as now and use my previous solution to detect XHR/Browser. This will save lot of effort and avoid creating separate handlers. We can keep same handlers and just implement request detection.**
Author
Owner

@bkrajendra commented on GitHub (Apr 20, 2019):

@vip20 i was suggesting header solution to have REST client to get JSON response, so that we can connect through app. There are some other issues like keeping portal open etc. thats totally different issues. Also im not getting what exactly you are asking? I generally use Development branch only, even if it breaks sometime :)

<!-- gh-comment-id:485166929 --> @bkrajendra commented on GitHub (Apr 20, 2019): @vip20 i was suggesting header solution to have REST client to get JSON response, so that we can connect through app. There are some other issues like keeping portal open etc. thats totally different issues. Also im not getting what exactly you are asking? I generally use Development branch only, even if it breaks sometime :)
Author
Owner

@vip20 commented on GitHub (Apr 20, 2019):

@bkrajendra I'll try to implement it tomorrow, I badly need this feature, have you ever tried with firebase connection with esp8266?

<!-- gh-comment-id:485168225 --> @vip20 commented on GitHub (Apr 20, 2019): @bkrajendra I'll try to implement it tomorrow, I badly need this feature, have you ever tried with firebase connection with esp8266?
Author
Owner

@bkrajendra commented on GitHub (Apr 20, 2019):

No @vip20 , I generally use my own VPS servers with cloud and mqtt on it.

<!-- gh-comment-id:485171596 --> @bkrajendra commented on GitHub (Apr 20, 2019): No @vip20 , I generally use my own VPS servers with cloud and mqtt on it.
Author
Owner

@tablatronix commented on GitHub (Apr 20, 2019):

I would rather implement an api endpoint and write custom api class, than have to add ajax checking to each callback just to keep it cleaner and be able to add features to api easier

<!-- gh-comment-id:485194086 --> @tablatronix commented on GitHub (Apr 20, 2019): I would rather implement an api endpoint and write custom api class, than have to add ajax checking to each callback just to keep it cleaner and be able to add features to api easier
Author
Owner

@rvhani commented on GitHub (Jan 1, 2020):

I'm waiting for this. Rest API. sory for 1-liner.

<!-- gh-comment-id:570024709 --> @rvhani commented on GitHub (Jan 1, 2020): I'm waiting for this. Rest API. sory for 1-liner.
Author
Owner

@vip20 commented on GitHub (Jan 3, 2020):

@bkrajendra have any luck on this?

<!-- gh-comment-id:570455117 --> @vip20 commented on GitHub (Jan 3, 2020): @bkrajendra have any luck on this?
Author
Owner

@laurensV commented on GitHub (Nov 27, 2022):

2.5 years later but would still be great to have this feature!

<!-- gh-comment-id:1328326919 --> @laurensV commented on GitHub (Nov 27, 2022): 2.5 years later but would still be great to have this feature!
Author
Owner

@laurensV commented on GitHub (Nov 27, 2022):

Or is there a different example of a wifimanger that exposes API endpoints so it can be setup through a mohile app for example?

<!-- gh-comment-id:1328327117 --> @laurensV commented on GitHub (Nov 27, 2022): Or is there a different example of a wifimanger that exposes API endpoints so it can be setup through a mohile app for example?
Author
Owner

@tablatronix commented on GitHub (Nov 28, 2022):

You can make your own api in user code

<!-- gh-comment-id:1328386604 --> @tablatronix commented on GitHub (Nov 28, 2022): You can make your own api in user code
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/WiFiManager#653
No description provided.