Handling different request from client [ESP8266] [WiFiServer] [ESP8266WebServer]

Hello!

I just got ultra confused about the part of the project that I am currently working on...It's about making HTTP request from C# app (acting as a client) to an ESP8266 which has to respond with JSON.

  1. I started with simple one, which was just responding to request like ("http://192.168.8.135") - just requesting ESP's IP adress. It worked fine, with usage of <ArduinoJson.h> I got beautiful JSON file in response.
    I used:
    WiFiServer server(80);
    server.begin();
    while(client.avaiilable())
    ...

  2. Then I found out that I need to distinguish TWO DIFFERENT requests coming from my C#app ( client ).
    Let's say one is ".../getFileList" and second ".../getCoords?fileName=123".
    And here is where the problems started occuring. I got confused about WiFiServer vs ESP8266WebServer. Why the first one has direct access to .client and lets me do sth like: serializeJsonPretty(doc, client);
    while the second one can only call server.handleClient() in loop method ? :o

The way I understood that: with ESP8266WebServer we can handle different requests with a nice method: server.on("","<method_name_to_handle_that>". So I would like to mix that with being able to print to a specific client that has just send me a request.

The question is: how am I able to respond to client DEPENDING ON REQUEST it sent ?
Which type of server would it be?

Please help, any tips will be appreciated...
Thanks!

Which type of server would it be?

You can use either one. Suppose that your task was to respond to two different people making requests. Would you set up your help desk with signs in Chinese and Russian describing what you can do? Of course not. You'd expect people needing help to ask for it in your native language.

So, pick a native language, either WiFiServer or ESP8266WebServer, and handle all the requests in that language.

If you like the capabilities of ESP8266WebServer with it's bizarre way of doing all the work for you, for determining what the client asked for, and choosing the right function to call to handle that request, then use that class.

If you like the ability of WiFiServer to handle some of the outgoing communications, then use that. It is not that difficult to collect the request from the client into a container and then parse the contents of the container, when the complete request has been received.

That container should be a NULL terminated array of chars, but I'm sure that most of the examples that you'll find for the ESP will use Strings.