+
+# Tnitter RESTful interface
+class TnitterREST
+ super Action
+
+ redef fun answer(request, turi)
+ do
+ if turi == "/list" then
+ # list?from=1&count=2 -> Error | Array[Post]
+
+ var from = request.int_arg("from") or else 0
+ var count = request.int_arg("count") or else 8
+
+ var db = new DB.open(tnitter_db_path)
+ var posts = db.list_posts(from, count)
+ db.close
+
+ var response = new HttpResponse(200)
+ response.body = posts.serialize_to_json
+ return response
+ end
+
+ # Format not recognized
+ var error = new Error("Bad Request")
+ var response = new HttpResponse(400)
+ response.body = error.serialize_to_json
+ return response
+ end
+end