vibe.d get parameters

Brian Forbes via Digitalmars-d digitalmars-d at puremagic.com
Thu May 5 18:39:54 PDT 2016


Hello,
     I have been programming in D now for a few months, and I am 
really impressed by how easy it is to get things up and running.
     However, I have run into some problems with vibe.d. I can't 
seem to figure out how to pass a get parameter after searching 
online for a few days.

     The code is more or less as below. I have tried lots of 
variations on how to add an input parameter (using something/:id 
etc) but everything gives a 404 error.

     Any help would be greatly appreciated. Thanks !

http://localhost:8081/something?id=a ( <---- this gives 404 )

import vibe.d;
import std.stdio;
import std.conv;
import std.json;

shared static this()
{
	auto router = new URLRouter;

	router.registerRestInterface(new ApiImpl);

	auto settings = new HTTPServerSettings;
	settings.port = 8081;
	listenHTTP(settings, router);

	logInfo("Please open http://127.0.0.1:8081/ in your browser.");
}

  interface Api
  {
      @method(HTTPMethod.GET) @path("/something/")
      string getSomething(string id);
  }

  class ApiImpl: Api
  {
      override:
          string getSomething(string id)
          {
              return id ~ "\nhello word";
          }
  }


More information about the Digitalmars-d mailing list