|
@@ -4,19 +4,39 @@ fun addHeaders () =
|
|
|
n <- now;
|
|
|
setHeader (blessResponseHeader "Date") (timef "%a, %d %b %Y %H:%M:%S GMT" n);
|
|
|
setHeader (blessResponseHeader "Server") "Ur/Web"
|
|
|
-
|
|
|
+fun clamp n =
|
|
|
+ (mod n 10000) + 1
|
|
|
+fun parseQueries oqs =
|
|
|
+ let
|
|
|
+ val qt = case oqs of
|
|
|
+ None => Some ("queries", "1")
|
|
|
+ | Some qs => String.split (show qs) #"="
|
|
|
+ val on = case qt of
|
|
|
+ None => Some 1
|
|
|
+ | Some ("queries", x) => read x
|
|
|
+ | Some _ => Some 1
|
|
|
+ in
|
|
|
+ case on of
|
|
|
+ None => 1
|
|
|
+ | Some x => if x > 500 then 500
|
|
|
+ else if x < 1 then 1
|
|
|
+ else x
|
|
|
+ end
|
|
|
+fun range n acc =
|
|
|
+ case n of
|
|
|
+ 0 => acc
|
|
|
+ | _ => range (n-1) (n :: acc)
|
|
|
|
|
|
val hello = "Hello, World!"
|
|
|
fun plaintext () =
|
|
|
addHeaders ();
|
|
|
returnBlob (textBlob hello) (blessMime "text/plain")
|
|
|
|
|
|
-
|
|
|
type json_t = {Message : string}
|
|
|
fun json () =
|
|
|
let
|
|
|
val json_conversion : json json_t = json_record {Message = "message"}
|
|
|
- val hello_json : json_t = {Message = hello}
|
|
|
+ val hello_json = {Message = hello}
|
|
|
in
|
|
|
addHeaders ();
|
|
|
returnBlob (textBlob (toJson hello_json)) (blessMime "application/json")
|
|
@@ -28,37 +48,12 @@ val world_conversion : json world_t = json_record {Id = "id", RandomNumber = "ra
|
|
|
fun world_find n =
|
|
|
oneRow1 (SELECT World.Id, World.RandomNumber FROM world WHERE World.Id = {[n]})
|
|
|
|
|
|
-fun clamp n =
|
|
|
- (mod n 10000) + 1
|
|
|
-
|
|
|
fun db () =
|
|
|
addHeaders ();
|
|
|
n <- rand;
|
|
|
row <- world_find (clamp n);
|
|
|
returnBlob (textBlob (toJson row)) (blessMime "application/json")
|
|
|
|
|
|
-fun parseQueries oqs =
|
|
|
- let
|
|
|
- val qt = case oqs of
|
|
|
- None => Some ("queries", "1")
|
|
|
- | Some qs => String.split (show qs) #"="
|
|
|
- val on = case qt of
|
|
|
- None => Some 1
|
|
|
- | Some ("queries", x) => read x
|
|
|
- | Some _ => Some 1
|
|
|
- in
|
|
|
- case on of
|
|
|
- None => 1
|
|
|
- | Some x => if x > 500 then 500
|
|
|
- else if x < 1 then 1
|
|
|
- else x
|
|
|
- end
|
|
|
-
|
|
|
-fun range n acc =
|
|
|
- case n of
|
|
|
- 0 => acc
|
|
|
- | _ => range (n-1) (n :: acc)
|
|
|
-
|
|
|
fun queries oqs =
|
|
|
addHeaders ();
|
|
|
let
|