Skip to content

Commit

Permalink
feat add http library
Browse files Browse the repository at this point in the history
  • Loading branch information
wirapratamaz committed May 22, 2024
1 parent 4225ad8 commit f18b3e3
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/currency/FXFactory.mo
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import Array "mo:base/Array";
import Blob "mo:base/Blob";
import Char "mo:base/Char";
import Cycles "mo:base/ExperimentalCycles";
import Debug "mo:base/Debug";
import HashMap "mo:base/HashMap";
import Hash "mo:base/Hash";
import Nat "mo:base/Nat";
import Nat32 "mo:base/Nat32";
import Nat64 "mo:base/Nat64";
import Option "mo:base/Option";
import Principal "mo:base/Principal";
import Text "mo:base/Text";
import Time "mo:base/Time";
import Trie "mo:base/Trie";
import TrieMap "mo:base/TrieMap";
import Buffer "mo:base/Buffer";
import Int "mo:base/Int";
import Iter "mo:base/Iter";
import Error "mo:base/Error";
import List "mo:base/List";
import AssocList "mo:base/AssocList";
import Float "mo:base/Float";
import Map "mo:map/Map";
import Types "../Types";
import Utils "../Utils";
import HttpTypes "../HttpTypes";
54 changes: 54 additions & 0 deletions src/http/http.mo
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
module Types {

public type Timestamp = Nat64;

//See: https://internetcomputer.org/docs/current/references/ic-interface-spec/#ic-http_request
public type HttpRequestArgs = {
url : Text;
max_response_bytes : ?Nat64;
headers : [HttpHeader];
body : ?[Nat8];
method : HttpMethod;
transform : ?TransformRawResponseFunction;
};

public type HttpHeader = {
name : Text;
value : Text;
};

public type HttpMethod = {
#get;
#post;
#head;
};

public type HttpResponsePayload = {
status : Nat;
headers : [HttpHeader];
body : [Nat8];
};

//2. HTTPS outcalls have an optional "transform" key. These two types help describe it.
//"The transform function may, for example, transform the body in any way, add or remove headers,
//modify headers, etc. "
//See: https://internetcomputer.org/docs/current/references/ic-interface-spec/#ic-http_request
public type TransformRawResponseFunction = {
function : shared query TransformArgs -> async HttpResponsePayload;
context : Blob;
};

// This Type defines the arguments the transform function needs.
public type TransformArgs = {
response : HttpResponsePayload;
context : Blob;
};

public type IC = actor {
http_request : HttpRequestArgs -> async HttpResponsePayload;
};

public type MainActor = actor {
transform_response : shared query TransformArgs -> async HttpResponsePayload;
};
};

0 comments on commit f18b3e3

Please sign in to comment.