Registering Web2 Webhooks

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:

  1. Is it possible for a canister to receive HTTP POST requests from external Web2 services?
  2. What are the limitations of canister HTTP calls regarding inbound requests?
  3. 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!

1 Like

No matter the HTTP method, the gateway will forward the request to http_request. You need to upgrade if you want to process the POST request in http_request_update.

I don’t know if you need to do anything special locally. Can you just try with curl?

1 Like