Hello everyone,
I’m new to developing canisters on the Internet Computer, and I’m working on integrating a canister with a traditional Web2 service. Specifically, my canister needs to:
- Make a POST request to the Web2 service.
- Register a callback endpoint for the Web2 service to send back a POST request with information.
I’m wondering if it’s possible to achieve this functionality on the Internet Computer, or if canisters only support outbound HTTP calls to Web2 services.
To test this locally, I created a basic canister:
import Text "mo:base/Text";
import HTTP "./Http";
actor {
type HttpRequest = HTTP.HttpRequest;
type HttpResponse = HTTP.HttpResponse;
// Query method for handling GET requests
public query func http_request(req : HttpRequest) : async HttpResponse {
let response : HttpResponse = {
status_code = 200;
headers = [("content-type", "text/html")];
body = Text.encodeUtf8("Hello from Internet Computer (GET)");
streaming_strategy = null;
upgrade = null;
};
return response;
};
// Update method for handling POST requests
public shared func http_request_update(req : HttpRequest) : async HttpResponse {
let response : HttpResponse = {
status_code = 200;
headers = [("content-type", "text/html")];
body = Text.encodeUtf8("Hello from Internet Computer (POST)");
streaming_strategy = null;
upgrade = null;
};
return response;
};
};
I’m unsure how to test sending a POST request to my canister when using dfx
locally.
My questions are:
- Is it possible for a canister to receive HTTP POST requests from external Web2 services?
- What are the limitations of canister HTTP calls regarding inbound requests?
- What is the best way to test receiving POST requests locally on the Internet Computer?
Any help or guidance would be greatly appreciated in understanding how to implement this functionality.
Thank you!