import Nat "mo:base/Nat";
import Text "mo:base/Text";
actor Counter {
public type Key = Text;
public type Path = Text;
public type Chunk_Id = Nat;
public type SetAssetContentArguments = {
key: Key;
sha256:?[Nat8];
chunk_ids: [Chunk_Id];
content_encoding: Text;
};
public type StreamingCallbackHttpResponse = {
token: ?StreamingCallbackToken;
body: Blob;
};
public type StreamingCallbackToken = {
key: Text;
sha256: ?[Nat8];
index:Nat;
content_encoding: Text;
};
public type StreamingStrategy = {
#Callback : {
token: StreamingCallbackToken;
Callback: shared query StreamingCallbackToken -> async StreamingCallbackHttpResponse;
};
};
public type HeaderField = (Text, Text);
public type HttpRequest = {
url: Text;
method: Text;
body: Blob;
headers: [HeaderField];
};
public type HttpResponse = {
body: Blob;
headers: [HeaderField];
streaming_strategy: ?StreamingStrategy;
status_code: Nat16;
};
public shared query func http_request(request: HttpRequest) : async HttpResponse {
{
body = Text.encodeUtf8("<html><body><h2>the counter is: " # Nat.toText(counter) # "</h2><body></html>");
headers = [];
streaming_strategy = null;
status_code= 200;
}
};
stable var counter = 0;
// Get the value of the counter.
public query func get() : async Nat {
return counter;
};
// Set the value of the counter.
public func set(n : Nat) : async () {
counter := n;
};
// Increment the value of the counter.
public func inc() : async () {
counter += 1;
};
};
网友评论