RejectedSoftware Forums

Sign up

Routing URI Into Web Interface Generator Function Parameters

First, I'd like to mention that I'm just starting out with Vibe.D and truly appreciate the work that has been done on it. It's wonderful having an approach to web development that is both compiled and straightforward to use.

I've been reading the source and documentation, and I can't seem to find a way to do the following:

# url.com/prefix/page/parameter1/parameter2
void getPage(string parameter1, string parameter2) {}

Now I know there's similar capability with the URLRouter, where I at least have access to those parameters via a request object:

router.get("/users/:user", &userInfo);
req.params["user"]

With the web interface generator, I can't (or don't know how to) specify parameters like :user. Does the functionality I'm looking for exist? How would I go about doing this?

Thanks for any help you can provide.

Re: Routing URI Into Web Interface Generator Function Parameters

On Mon, 27 Oct 2014 17:39:54 GMT, Dylan Allbee wrote:

First, I'd like to mention that I'm just starting out with Vibe.D and truly appreciate the work that has been done on it. It's wonderful having an approach to web development that is both compiled and straightforward to use.

I've been reading the source and documentation, and I can't seem to find a way to do the following:

# url.com/prefix/page/parameter1/parameter2
void getPage(string parameter1, string parameter2) {}

Now I know there's similar capability with the URLRouter, where I at least have access to those parameters via a request object:

router.get("/users/:user", &userInfo);
req.params["user"]

With the web interface generator, I can't (or don't know how to) specify parameters like :user. Does the functionality I'm looking for exist? How would I go about doing this?

Thanks for any help you can provide.

Off the top of my head:

@path("/prefix/page/:parameter1/:parameter2")
void getPage(string _parameter1, string _parameter2)
{
	// ...
}

The @path attribute overrides the usual inferred path ("/page" in this case) and supports the variable placeholder syntax of URLRouter. Any parameter prefixed by an underscore will be taken from HTTPServerRequest.params instead of .form or .query, so that they will receive the placeholder values in this case.

Re: Routing URI Into Web Interface Generator Function Parameters

That's fantastic, thank you.

Hopefully as I get more comfortable with this framework, I'll be able to help others with it as well. When our team is done with the project, we'll be open sourcing the code and sharing it with the community.

All the best,
Dylan