The latest episode of Uber Leet Hacker Force Radio is out. I did a quick interview near the end of the show. I talked a little about D and Rootin Tootin. This may be interesting to people who want to learn more about D, and my motivations for creating Rootin Tootin.
Uber Leet Hacker Force Radio is syndicated on Hacker Public Radio. The episode can be directly downloaded from here.
The other day I started porting the Tornado web server to D. I just got the IO Loop part ported. I’m planning on using this in my web framework Rootin Tootin.
You can check out the code on Launchpad: http://launchpad.net/dornado. Next I will add proper Epoll and the HTTP part. But in the meantime, you can try it out with this demo code snippet:
private import tango.net.device.Socket;
private import tango.io.model.IConduit;
private import tango.net.InternetAddress;
private import tango.io.Stdout;
public import ioloop;
class HelloServer {
private ServerSocket sock;
private char[1024] buffer;
public void handle_connection(Socket connection, char[] address) {
connection.read(buffer);
connection.write("hello world!");
connection.shutdown();
connection.detach();
}
public void connection_ready(ServerSocket sock, ISelectable.Handle fd, uint events) {
while(true) {
Socket connection = sock.accept();
connection.socket.blocking(false);
handle_connection(connection, "");
}
}
public void call_connection_ready(ISelectable.Handle fd, uint events) {
connection_ready(sock, fd, events);
}
public void start() {
int port = 3000;
int max_waiting_clients = 128;
bool reuse_address = true;
this.sock = new ServerSocket(new InternetAddress("0.0.0.0", port), max_waiting_clients, reuse_address);
this.sock.socket.blocking(false);
auto io_loop = IOLoop.instance();
auto callback = &this.call_connection_ready;
io_loop.add_handler(this.sock.fileHandle, callback, io_loop.READ);
Stdout("http://localhost:3000").newline.flush;
io_loop.start(sock);
}
}
public void main() {
IOLoop.use_epoll = false;
auto server = new HelloServer();
server.start();
}
You can compile this with:
ldc helloworld.d ../ioloop.d ../language_helper.d
Tuesday, January 19, 2010
I just released Rootin Tootin 0.3.0. In case you don’t know what it is: Rootin Tootin is a fast RESTful web server and framework written in D. It is designed to scale well by default, while still providing a developer experience similar to Ruby on Rails.
I don’t want to transpose the changelog here. You can view that at your leisure. Instead here are my highlights. Firstly, you can now use the link_to function in views to generate links. It will automatically add the .html to the end if needed. Secondly, and most awesomely: it now works properly with REST and Active Resource. You can even use the rails active resource, and python active resource to talk to it:
Lets start by creatnig a simple web app to talk too:
rootintootin name:users port:3000 db_user:root db_password:letmein
cd journal
./gen recreate database
./gen create noun singular:user plural:users
./gen create scaffold note name:string email:string
./gen migrate
./run
Now lets try talking to it, with the rails active resource:
#!/usr/bin/env ruby
require 'rubygems'
require 'active_resource'
class User < ActiveResource::Base
self.site = "http://localhost:3000"
end
# create
user = User.new
user.name = "mr possum"
user.email = "possum@gmail.com"
user.save
# update
User.find(:all).each do |user|
user.name = "awesome possum"
user.save
end
# delete
user = User.find(:first)
user.destroy
# read
User.find(:all).each do |user|
puts "name #{user.name} email #{user.email}"
end
If you are feeling more dangerous, you can try the python active resource version:
#!/usr/bin/env python
from pyactiveresource.activeresource import ActiveResource
class User(ActiveResource):
_site = "http://localhost:3000"
# create
user = User()
user.name = "mr possum"
user.email = "possum@gmail.com"
user.save()
# update
for user in User.find():
user.name = "awesome possum"
user.save
# delete
user = User.find_first()
user.destroy()
# read
for user in User.find():
print "name {0} email {1}".format(user.name, user.email)
So neat. This is just a small sample of what you can do. But there are still many essential features that need to be added. Not to mention html 5 goodness, like websocks and access control.
I’ll try and add a video walk-through of a basic app later. Bye Bye for now.