Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-105365

An easier way to repeatedly create routes with the same basepath

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Unresolved
    • Not Evaluated
    • None
    • None
    • Qt Http Server
    • None

    Description

      Currently you have to write something like
       

      QHttpServer server;
      server.addRoute("/api/something", ...);
      server.addRoute("/api/somethingelse", ...);
      server.addRoute("/api/anotherthing", ...);
      

      What would be nice is if the /api/ part could be omitted somehow, a suggestion I have is a new class that would enable something like this:

      QHttpServer server;
      auto api = server.withBasePath("/api");
      api.addRoute("/something", ...);
      api.addRoute("/somethingelse", ...);
      api.addRoute("/anotherthing", ...);
      

      Not only would this make it look cleaner, if it worked 'recursively' it would also make enabling support for reverse proxying with a base path much easier, and wouldn't need to permeate every single addRoute call, nor would there need to be a global setBasePath that affects the whole server. If your setup previously looked like the snippet above you could just make the change as below:

      QHttpServer server;
      auto base = server.withBasePath("/myservice")
      auto api = base.withBasePath("/api");
      api.addRoute("/something", ...); // => the path for this route is /myservice/api/something
      ...
      

      Attachments

        Activity

          People

            mikhailsvetkin Mikhail Svetkin
            manordheim Mårten Nordheim
            Vladimir Minenko Vladimir Minenko
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: