Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. REST request with an regular expressions in a URL

REST request with an regular expressions in a URL

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 4 Posters 1.9k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Beatnicker
    wrote on 15 Nov 2021, 20:18 last edited by
    #1

    I want to create a GET request using the REST API.
    The GET API also understands regular expressions (http://ocalhost:8084/rest/channel/.*/Active.Power ).
    But I get an error message when I use this url, because Wireshark told me that the url looks like this: http://ocalhost:8084/rest/channel//ActivePower. And this cannot be computed by the server.
    I was not able to accept that request the "
    ".
    Does anyone know how to prepare the networkrqeust or the url so that Qt uses the correct url for get request?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 15 Nov 2021, 20:27 last edited by
      #2

      Hi and welcome to devnet,

      You are expected to replace the .* with something sensible like a string or channel number.

      Note that this is regular expression is likely wrong as URL usually do not use two slashes one after the other. I would expect something more precise especially when dealing with a REST service.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • B Offline
        B Offline
        Beatnicker
        wrote on 15 Nov 2021, 21:02 last edited by
        #3

        I don't want to replace the '.*' with a regular expression. I want to read all ActivePower and ReactivePower of all channels, see description with of the interface. https://openems.github.io/openems.io/openems/latest/edge/controller.html#_get

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mchinand
          wrote on 15 Nov 2021, 21:38 last edited by
          #4

          Does the url you are trying to use with a QNetworkRequest work when you use it in a browser?

          1 Reply Last reply
          0
          • B Offline
            B Offline
            Beatnicker
            wrote on 15 Nov 2021, 22:14 last edited by
            #5

            It works with the Talend API Tester.

            S 1 Reply Last reply 16 Nov 2021, 08:32
            1
            • K Offline
              K Offline
              Kent-Dorfman
              wrote on 15 Nov 2021, 22:26 last edited by Kent-Dorfman
              #6

              @Beatnicker said in REST request with an regular expressions in a URL:

              The GET API also understands regular expressions (http://ocalhost:8084/rest/channel/.*/Active.Power ).

              A URL sent to a server must be a distinct resolvable location, not a wildcard. If you've got a server that's allowing something like that then it's violating the standard.

              The URL must distinctly resolve. If you need to send wildcards then they must be supplied as params to the GET/PUT operation.

              I looked at the referenced docs and they are doing something that is not going to be well supported. IOW, their API kind of sucks. To do what they suggest in a transportable way they should do http://hostname.com/something?wildcards_allowed_here_but_not_before_question_mark

              1 Reply Last reply
              3
              • B Beatnicker
                15 Nov 2021, 22:14

                It works with the Talend API Tester.

                S Offline
                S Offline
                SGaist
                Lifetime Qt Champion
                wrote on 16 Nov 2021, 08:32 last edited by
                #7

                @Beatnicker I think I understand the issue a bit better now.

                The way you formulated it made it look like an issue server side where lots of framework allow to define their path using regular expressions like Django's URL dispatcher does.

                For example re_path(r'^articles/(?P<year>[0-9]{4})/$', views.year_archive)

                In your case the API does not understand regular expression at all, it's in fact a special path named ".*".

                I did a quick test on Python and its HTTPServer class and got the path correctly requested using QUrl("http://localhost:8080/test/.*/Active.Power").

                I would advise to provide a minimal compilable example using QNetworkAccessManager to ensure we are looking at the correct problem.

                Adding the Qt version you are using as well as OS would be a good idea.

                Is there any test instance of OpenEMS that can be queried ? Or an easy way to start it locally ?

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                1
                • B Offline
                  B Offline
                  Beatnicker
                  wrote on 17 Nov 2021, 17:19 last edited by
                  #8

                  It is not possible to provide you a test instance and it is also not quite easy to set it up quickly

                  I'm using Qt 5.12.8 und Linux Mint 20.2 Cinnamon and this my example:

                  #include <QCoreApplication>
                  #include <QNetworkAccessManager>
                  #include <QNetworkReply>
                  #include <QNetworkRequest>
                  #include <QUrl>
                  
                  
                  
                  int main(int argc, char *argv[])
                  {
                      QCoreApplication a(argc, argv);
                  
                      QNetworkAccessManager manager;
                      QNetworkRequest request;
                      qWarning() << "http://192.168.0.125:8086/rest/channel/.*/.*Temperature";
                      QUrl url = QUrl("http://192.168.0.125:8086/rest/channel/.*/.*Temperature");
                      request.setUrl(url);
                  
                      // HTTP Basic authentication header value:
                      request.setRawHeader("Authorization", "Basic QWRtaW46YWRtaW4=" );
                      request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
                  
                  
                  
                      QObject::connect(&manager, &QNetworkAccessManager::finished, &a, [](QNetworkReply * reply){
                          if(reply->error())
                          {
                              qWarning() << "ERROR!";
                              qWarning() << reply->errorString();
                  
                          }
                          else
                          {
                              qWarning() << "OK";
                          }
                  
                      });
                  
                      manager.get(request);
                  
                      return a.exec();
                  
                  }
                  

                  these are the outputs of the console

                  http://192.168.0.125:8086/rest/channel/.*/.*Temperature
                  ERROR!
                  "Error transferring http://192.168.0.125:8086/rest/channel/.*/.*Temperature - server replied: Not Found"
                  

                  and even screenshots from Wireshark
                  786943f4-3752-4a39-be05-d127332ae10e-image.png
                  0ae37f48-fc13-498c-b7c5-c9fc2036269a-image.png

                  I also take a screenshot from Wireshark with Talent API Tester. You can see that the url transferred correctly as expected.
                  b392cd67-abae-4b73-9a3e-147b60fcd459-image.png

                  I hope that I have described the problem even better?

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    mchinand
                    wrote on 17 Nov 2021, 17:42 last edited by
                    #9

                    @Beatnicker said in REST request with an regular expressions in a URL:

                    "http://192.168.0.125:8086/rest/channel/.*/.*Temperature"

                    It's interesting that only your first wildcard in your url is being removed when sending via Qt. Not sure why that is though.

                    1 Reply Last reply
                    0

                    4/9

                    15 Nov 2021, 21:38

                    • Login

                    • Login or register to search.
                    4 out of 9
                    • First post
                      4/9
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved