Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
run: npm run test:e2e

- name: Clean Up
run: killall dfx replica
run: dfx killall

aggregate:
name: e2e:required
Expand Down
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,3 @@ These functions are used internally by the library, but are also exported for us
- Encodes a request as a blob
- `public func yieldResponse(b : HttpResponse) : Blob`
- Encodes a response as a blob

## Credits

This project currently copies the `http-parser` library into its source tree. This is because the `http-parser` library is not currently installable as a package on `mops`. Source code is available at https://github.com/NatLabs/http-parser.mo
5 changes: 4 additions & 1 deletion canister_ids.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@
},
"test": {
"ic": "qpyq6-kiaaa-aaaab-qaidq-cai"
},
"http_greet": {
"ic": "qg33c-4aaaa-aaaab-qaica-cai"
}
}
}
2 changes: 1 addition & 1 deletion dfx.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
},
"defaults": {
"build": {
"packtool": "mops sources"
"packtool": "npx mops sources"
}
}
}
16 changes: 0 additions & 16 deletions examples/http_greet/dfx.json

This file was deleted.

3 changes: 2 additions & 1 deletion examples/http_greet/mops.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
[package]
name = "http_hello"
version = "0.1.0"
version = "1.0.0"
description = ""
repository = ""

[dependencies]
certified-cache = "0.2.0"
assets = "0.2.0"
http-parser = "0.3.1"
40 changes: 20 additions & 20 deletions examples/http_greet/src/http_greet/main.mo
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ shared ({ caller = creator }) actor class () {

server.post(
"/greet",
func(req : Request, res : ResponseClass) : async* Response {
func(req : Request, res : ResponseClass) : async Response {
let parsedName = req.url.queryObj.get("name");
var name = "";
switch parsedName {
Expand All @@ -42,7 +42,7 @@ shared ({ caller = creator }) actor class () {

server.get(
"/foo",
func(req : Request, res : ResponseClass) : async* Response {
func(req : Request, res : ResponseClass) : async Response {
res.send({
status_code = 200;
headers = [("Content-Type", "text/html")];
Expand All @@ -53,14 +53,14 @@ shared ({ caller = creator }) actor class () {
},
);

public shared ({ caller }) func authorize(other : Principal) : async* () {
public shared ({ caller }) func authorize(other : Principal) : async () {
server.authorize({
caller;
other;
});
};

public query func retrieve(path : Assets.Path) : async* Assets.Contents {
public query func retrieve(path : Assets.Path) : async Assets.Contents {
assets.retrieve(path);
};

Expand All @@ -72,14 +72,14 @@ shared ({ caller = creator }) actor class () {
content : Blob;
sha256 : ?Blob;
}
) : async* () {
) : async () {
server.store({
caller;
arg;
});
};

public query func list(arg : {}) : async* [T.AssetDetails] {
public query func list(arg : {}) : async [T.AssetDetails] {
assets.list(arg);
};

Expand All @@ -88,7 +88,7 @@ shared ({ caller = creator }) actor class () {
key : T.Key;
accept_encodings : [Text];
}
) : async* ({
) : async ({
content : Blob;
content_type : Text;
content_encoding : Text;
Expand All @@ -98,7 +98,7 @@ shared ({ caller = creator }) actor class () {
assets.get(arg);
};

public shared ({ caller }) func create_batch(arg : {}) : async* ({
public shared ({ caller }) func create_batch(arg : {}) : async ({
batch_id : T.BatchId;
}) {
assets.create_batch({
Expand All @@ -112,7 +112,7 @@ shared ({ caller = creator }) actor class () {
batch_id : T.BatchId;
content : Blob;
}
) : async* ({
) : async ({
chunk_id : T.ChunkId;
}) {
assets.create_chunk({
Expand All @@ -121,42 +121,42 @@ shared ({ caller = creator }) actor class () {
});
};

public shared ({ caller }) func commit_batch(args : T.CommitBatchArguments) : async* () {
public shared ({ caller }) func commit_batch(args : T.CommitBatchArguments) : async () {
assets.commit_batch({
caller;
args;
});
};

public shared ({ caller }) func create_asset(arg : T.CreateAssetArguments) : async* () {
public shared ({ caller }) func create_asset(arg : T.CreateAssetArguments) : async () {
assets.create_asset({
caller;
arg;
});
};

public shared ({ caller }) func set_asset_content(arg : T.SetAssetContentArguments) : async* () {
public shared ({ caller }) func set_asset_content(arg : T.SetAssetContentArguments) : async () {
assets.set_asset_content({
caller;
arg;
});
};

public shared ({ caller }) func unset_asset_content(args : T.UnsetAssetContentArguments) : async* () {
public shared ({ caller }) func unset_asset_content(args : T.UnsetAssetContentArguments) : async () {
assets.unset_asset_content({
caller;
args;
});
};

public shared ({ caller }) func delete_asset(args : T.DeleteAssetArguments) : async* () {
public shared ({ caller }) func delete_asset(args : T.DeleteAssetArguments) : async () {
assets.delete_asset({
caller;
args;
});
};

public shared ({ caller }) func clear(args : T.ClearArguments) : async* () {
public shared ({ caller }) func clear(args : T.ClearArguments) : async () {
assets.clear({
caller;
args;
Expand All @@ -165,7 +165,7 @@ shared ({ caller = creator }) actor class () {

public type StreamingStrategy = {
#Callback : {
callback : shared query StreamingCallbackToken -> async* StreamingCallbackHttpResponse;
callback : shared query StreamingCallbackToken -> async StreamingCallbackHttpResponse;
token : StreamingCallbackToken;
};
};
Expand All @@ -182,14 +182,14 @@ shared ({ caller = creator }) actor class () {
token : ?StreamingCallbackToken;
};

public query func http_request_streaming_callback(token : T.StreamingCallbackToken) : async* StreamingCallbackHttpResponse {
public query func http_request_streaming_callback(token : T.StreamingCallbackToken) : async StreamingCallbackHttpResponse {
assets.http_request_streaming_callback(token);
};
public query func http_request(req : HttpRequest) : async* HttpResponse {
public query func http_request(req : HttpRequest) : async HttpResponse {
server.http_request(req);
};
public func http_request_update(req : HttpRequest) : async* HttpResponse {
await* server.http_request_update(req);
public func http_request_update(req : HttpRequest) : async HttpResponse {
await server.http_request_update(req);
};

/**
Expand Down
4 changes: 3 additions & 1 deletion examples/http_greet/src/http_greet/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const Ids = require("../../.dfx/local/canister_ids.json");
const HOST = `http://127.0.0.1:4943`;
// const HOST = "https://icp-api.io";
// const canisterId = Ids["http_greet"]["local"];
const canisterId = "br5f7-7uaaa-aaaaa-qaaca-cai";
const canisterId = "u6s2n-gx777-77774-qaaba-cai";
// const canisterId = "qg33c-4aaaa-aaaab-qaica-cai";

console.log(`canisterId: ${canisterId}`);
Expand All @@ -30,6 +30,8 @@ seed.fill(0);

const testIdentity = Ed25519KeyIdentity.generate(seed);

console.log(`testIdentity: ${testIdentity.getPrincipal().toText()}`);

// spawn shell command
const { spawn } = require("child_process");
const child = spawn("dfx", [
Expand Down
18 changes: 9 additions & 9 deletions examples/test/test.mo
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ shared ({ caller = creator }) actor class () {

server.get(
"/",
func(_ : Request, res : ResponseClass) : async* Response {
func(_ : Request, res : ResponseClass) : async Response {
res.send({
status_code = 200;
headers = [("Content-Type", "text/html")];
Expand All @@ -36,7 +36,7 @@ shared ({ caller = creator }) actor class () {
// Cached endpoint
server.get(
"/hi",
func(_ : Request, res : ResponseClass) : async* Response {
func(_ : Request, res : ResponseClass) : async Response {
res.send({
headers = [("Content-Type", "text/plain")];
status_code = 200;
Expand All @@ -49,7 +49,7 @@ shared ({ caller = creator }) actor class () {

server.get(
"/json",
func(_ : Request, res : ResponseClass) : async* Response {
func(_ : Request, res : ResponseClass) : async Response {
res.json({
status_code = 200;
body = "{\"hello\":\"world\"}";
Expand All @@ -60,7 +60,7 @@ shared ({ caller = creator }) actor class () {

server.get(
"/404",
func(_ : Request, res : ResponseClass) : async* Response {
func(_ : Request, res : ResponseClass) : async Response {
res.send({
status_code = 404;
headers = [("Content-Type", "text/plain")];
Expand All @@ -80,7 +80,7 @@ shared ({ caller = creator }) actor class () {
// Dynamic endpoint
server.get(
"/queryParams",
func(req : Request, res : ResponseClass) : async* Response {
func(req : Request, res : ResponseClass) : async Response {
let obj = req.url.queryObj;
let keys = Iter.fromArray(obj.keys);

Expand Down Expand Up @@ -129,7 +129,7 @@ shared ({ caller = creator }) actor class () {

server.get(
"/cats",
func(_ : Request, res : ResponseClass) : async* Response {
func(_ : Request, res : ResponseClass) : async Response {
var catJson = "[";
for (cat in Iter.fromArray(cats)) {
catJson := catJson # displayCat(cat) # ",";
Expand All @@ -147,7 +147,7 @@ shared ({ caller = creator }) actor class () {

server.get(
"/cats/:name",
func(req : Request, res : ResponseClass) : async* Response {
func(req : Request, res : ResponseClass) : async Response {
switch (req.params) {
case null {
res.send({
Expand Down Expand Up @@ -224,7 +224,7 @@ shared ({ caller = creator }) actor class () {

server.post(
"/cats",
func(req : Request, res : ResponseClass) : async* Response {
func(req : Request, res : ResponseClass) : async Response {
let body = req.body;
switch body {
case null {
Expand Down Expand Up @@ -271,7 +271,7 @@ shared ({ caller = creator }) actor class () {
server.http_request(req);
};
public func http_request_update(req : HttpRequest) : async HttpResponse {
await* server.http_request_update(req);
await server.http_request_update(req);
};

public func invalidate_cache() : async () {
Expand Down
Loading