rustinternet-computermotokodfinity

API calls for third party HTTP restful API from dfinity canisters


I m trying to find a way to make Restful API calls from Canisters (for SSO with OAuth) with Motoko but never found any library that.

Is there any HTTP client library available for Motoko? Is not is there a way to import any HTTP client library from another language such as Rust, C++, ... with Motoko? If not is it possible tto do it with Rust by importing an HTTP client library for rust?

If it's not possible to doing from the canisters, if it there any services in the Internet-Computer or Dfinity (ou any web3 solutions) to perform tasks like serverless functions like major cloud solutions to perform this simple task?

Thanks


Solution

  • As demonstrated during the first public Global R&D, an example of canister HTTP request Rust sample dApp retrieving exchange rate between ICP and USDC using the Coinbase API has been published to dfinity/examples GitHub repository.

    This example is lacking a Motoko equivalent but fundamentally there isn't any obstacle to do it as the canister HTTP request is relying on inter-canister call to the management canister.

    Otherwise you can deploy a Rust canister making the canister HTTP request and interact with this canister in Motoko to keep your codebase in Motoko while not having to translate the canister HTTP request in Motoko (but IMO it should be quite easy to translate to Motoko as there isn't much code and the dependencies are Motoko friendly).

    For more documentation, you may find out candid specification for http_request management canister endpoint here and the technical specification here.