Allow a numberrange in URL without "uriRegex.h"

Hello again!

I'm looking for some advice for my Webserver.
from my application i get a POST request with an empty body. So that means i get a POST request and all the info I need I get from the URL which my application is sending to.

All reachable URL's should cover those cases, but without initialising each and everyone, one by one:
IP/command/on or off/number between 1-n

So for Example if i want to turn off my led on pinnumber 20 i send my POST request on the following URL:


At first I fixed this problem by the following line of Code:

server.on(UriRegex("^\\/command\\/([on,off]+)\\/([0-9]+)$"),handlePostRequest );

But now i can't use the WebServer.h library anymore and to be honest, this wasnt really a good solution, since the only thing that happened is, that i allow number in the URL between 1 and 9.

Now i want to ask if someone knows a more "elegant" way to work around that problem.

Thanks in advance!

So why exactly do you use a POST request instead of a simple GET request?

Tokenize at the '/' character and parse each token separately.

why? Did your instructor forbit it?

I had to switch over to https. And I’m using a 3rd party library, since I didn’t found a arduino Library. This library provides a wrapper, so I can use it with the WebServer.h API so I don’t have to rewrite my code

So why exactly do you use a POST request instead of a simple GET request?

Because my instructor told me to. Sadly I’m new at the company and I don’t want to start a discussion.

Tokenize at the '/' character and parse each token separately.

What do you mean by tokenize ?


I don't understand what is your problem, explain better

And, your regex looks wrong, this part ([on,off]+) should be (on|off) (and also you could replace [0-9] by \d)

Hello @guix ,

yeah sure.

So basically i got an application. and i want the application to communicate with my webserver. To communicate with my webserver i use a 3rd-person library to implement HTTPS.

The communication im talking about should be done by a bodyless HTTPS POST request. All my Information I should receive by getting all the Data in my URL.

Basically i want to give the application 2 parameters to choose of. 1.= On or Off and 2. = number between 1 and x(lets say 32).

So for example the URL look like this: https://myipadress/command/on/5

that means i send a on signal for the number 5(could be a LED or anything else).

But before I'm able to reach my webserver with this URL I have to initialize this exact URL with the server.on() function.

and there's my problem. I dont want to initialize every URL one by one. Is there a possibillity without using UriRegex where i can say = just accept requests by the number between 1 and 32.

I don't know much about this, but normally parameters are done like this:

See this example

Yeah i would also do the same. But since i didn't make the app, i cant really change the way it is. So I'm getting a path and not really a value. I think this makes it more clear.

Maybe with server.onNotFound then in its handler function you parse server.uri() to get the parameters? Just an idea, I really don't know if that will work

1 Like

I'm not sure. But i think this is not the way to go. I solved it now, by initializing every single one with a for-loop now.

But thanks for your advice anyways!