Http_request url extract pathname, search, params, etc

Does anyone has an open source Motoko function to share that extract the information of an url intercepted by http_request?

public shared query({caller}) func http_request({method: Text; url: Text;} : HttpRequest) : async HttpResponse {
     let {hostname; pathname; search} = myCoolFunction(url);
...

Found a regex on SO (a bit ashamed I did not write it by myself) but, not sure how to use it with Text.split which does not seem to support regex.

^(([^:\/?#]+):)?(\/\/([^\/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?

Source language agnostic - Getting parts of a URL (Regex) - Stack Overflow

2 Likes

Yeah, no regex engine in Motoko yet. Someone would have to (and should) write a library for HTTP stuff for Motoko! (Likely easier than a full-blown regex engine)

3 Likes