Thread overview
How to web programming with D2?
Feb 10, 2011
canalpay
Feb 11, 2011
Stephan Soller
February 10, 2011
I am trying to write the web framework(but not to write, to gain experience.). Maybe the framework can has got a MVC  desing pattern. But first, the D2 is not has got for the web library and I am decided write to library for web.

I am writed a function for post and get methods. (I am not tried to functions. But I think, they are works.)
POST: https://github.com/canalpay/turna/blob/master/library/post.d
GET  :  https://github.com/canalpay/turna/blob/master/library/get.d

Environment variables are easy to write for the function.
But How to write a cookie and session?
I looked at the codes of tango. However, don't understand.(I'm new to d programming language.)
February 10, 2011
On Thu, 10 Feb 2011 04:29:21 -0500, canalpay wrote:

> I am trying to write the web framework(but not to write, to gain experience.). Maybe the framework can has got a MVC  desing pattern. But first, the D2 is not has got for the web library and I am decided write to library for web.
> 
> I am writed a function for post and get methods. (I am not tried to functions. But I think, they are works.) POST: https://github.com/canalpay/turna/blob/master/library/post.d GET  : https://github.com/canalpay/turna/blob/master/library/get.d
> 
> Environment variables are easy to write for the function. But How to write a cookie and session? I looked at the codes of tango. However, don't understand.(I'm new to d programming language.)

Adam D. Ruppe does a lot of web development in D, and he has created a fairly extensive web-dev library.

  http://arsdnet.net/dcode/

For cookie/session handling, cgi.d is probably the place to look.

-Lars
February 11, 2011
On 10.02.2011 10:29, canalpay wrote:
> I am trying to write the web framework(but not to write, to gain experience.). Maybe the framework can has got a MVC  desing pattern. But first, the D2 is not has got for the web library and I am decided write to library for web.
>
> I am writed a function for post and get methods. (I am not tried to functions. But I think, they are works.)
> POST: https://github.com/canalpay/turna/blob/master/library/post.d
> GET  :  https://github.com/canalpay/turna/blob/master/library/get.d
>
> Environment variables are easy to write for the function.
> But How to write a cookie and session?
> I looked at the codes of tango. However, don't understand.(I'm new to d programming language.)

From your code I assume you're using CGI. To set a cookie you have to set the "Set-Cookie" header with a string a specific format (see "Cookies on Wikipedia" link). In CGI the standard output of the program is used as HTTP response and therefore you can set headers by printing them first to stdout. After you're done writing headers (one per line usually) output an empty line. This marks the rest of the output as actual content of the response. So basically your program should output something like this:

	Content-Type: text/html
	Set-Cookie: name=value
	
	<html>
	…
	</html>

Depending on how you like to develop the RFCs for CGI and HTTP might come in handy. I sometimes also use Wikipedia to get an overview of the topic.

- Cookies on Wikipedia: http://en.wikipedia.org/wiki/HTTP_cookie
- HTTP on Wikipedia: http://en.wikipedia.org/wiki/Http
- CGI on Wikipedia: http://en.wikipedia.org/wiki/Common_Gateway_Interface
- CGI RFC: http://tools.ietf.org/html/rfc3875
- HTTP RFC: http://tools.ietf.org/html/rfc2616


Happy programming
Stephan Soller