Reputation: 934
I'm currently working on the stable version of Rascal and I want to spawn the Rascal webserver to serve my html templates with javascript functions.
Looking at the Webserver module I can't see how to use the serve function to use the webserver. It asks for a location (I'm assuming that the location would be something like |http://localhost:8080|
) and a callback that has the type of Response (Request)
but what is that type? I don't know how to create this kind of type and what it exactly is.
Upvotes: 1
Views: 158
Reputation: 4276
The type
Response (Request) callbackis a function, E.g.:
Response (Request r) { return response(...); }
This function is an anonymous function (it has no name) that you can pass into the serve function as an argument, you can also define it as a normal function with a name, and just put the name of that function as the argument.
So this would probably work:
serve(|http://localhost:8080|, Response (Request r){ return response("Hello world"); }):
Since there is a factory method
Response response(str content)in Webserver.rsc, that will create a response for you from a string argument.
Upvotes: 2
Reputation: 6696
In the absence of documentation about this module, all you can do is read the source. In the Eclipse browser, the libraries are accessible (indicated by little jar icons) and you'll find util::Webserver
there with the definition of the Response
and Request
types.
Basically Request
is a callback function with all the HTTP headers and stuff as parameters and Response
is a wrapper with alternative response types (files, strings, etc.).
Note that the current version is quite a bit different from the stable version you use, so reading code on github will not help much.
Upvotes: 2