On Mon, 16 Feb 2015 18:42:32 +0100, Andre wrote:

Am 15.02.2015 um 13:10 schrieb Mathias LANG:

On Thu, 12 Feb 2015 22:19:15 +0100, Andre wrote:

Hi,

I try to retrieve from a RestInterface a SessionVar which was
set from a WebInterface.
This is forbidden currently. How could I solve this issue?

The REST module aims for M2M (machine-to-machine) communication, while the web module aims for user-to-machine.
Even if they seem very similar, they are not compatible and should not be used together.

This is my use case:
OpenUI5 is a Javascript UI libary. It mainly retrieves data by using
OData services. You implement your UI / UI logic using xml and a model,
view, controller concept in JavaScript.

I try to implement a scenario similiar to vibe-d/examples/web. But
instead using Diet as UI, I am using OpenUI5.

I am facing one big issue. In my UI I have also username/password fields
and I am also calling SampleService.postLogin which also sets the
SessionVar "settings".
For getting some data I use the vibe.d RestInterface. But now,
I cannot access the SessionVar because this is forbidden.
I would like to check whether the user is already authenticated by the
WebInterface.

Kind regards
André

Where are you using RestInterfaceClient from ? From what I understand, you only have a server app, so you should not use a RestInterfaceClient (unless you are querying another RESTful API).

This is the way how OpenUI5 is implemented. You build an user interface
in javascript. The model (data) is an OData service. In my use case I
want to write a server app, which is an http server for the javascript
files but also provides different OData services consumed by the
javascript files.

I am not using RestInterfaceClient but the RestInterface as base for the
OData services.

The behavior I describe here I already saw running with nodeJs as
backend server application.

Kind regards
André

Do you need something specific of the REST interface generator other than JSON responses? If not, you could alternatively return Json from a web interface method and it will automatically be sent in string form. A JSON request body will not be mapped to parameters, though. But this could be done with a @before annotation for example.

But if you really want to access a session variable from a "REST" interface, then you could directly access it through the request class by using an @before annotation (untested):

class MyRestService {
	@before!getSomeSessionVar("_someSessionVar")
	void postSomeRestStuff(int someparam, string _someSessionVar)
	{
		// ...
	}
}

private static string getSomeSessionVar(HTTPServerRequest req, HTTPServerResponse res)
{
	return req.session.get!string("someSessionVar");
}

If this needs to be done for many methods, an alias can make it shorter:

class MyRestService {
	@extractSomeSessionVar
	void postSomeRestStuff(int someparam, string _someSessionVar)
	{
		// ...
	}
}

string getSomeSessionVar(HTTPServerRequest req, HTTPServerResponse res)
{
	return req.session.get!string("someSessionVar");
}

enum extractSomeSessionVar = before!getSomeSessionVar("_someSessionVar");