Home / News / Bounty - ICDevs.org - HTTPRequest Parser
Austin Fatheree, January 11 2022
This bounty gives the opportunity to
The developer will need to create a vessel package called HttpRequestParser that parses the HTTPRequest type into a more useable and extensible object. We suggest:
{
method: Text;
url: {
original: Text;
protocal: Text //http or https - may always be https?;
port: Nat16; //maybe always 443? What about local replica?
host: {
original: Text;
array: Array<Text>; // host split at the "."s
};
path: {
original: Text;
array: Array<Text>; // split path by "/" into an array that can be referenced;
};
query: {
original: Text; //everything after the ? and before an anchor
get: (Text) -> ?Text; //helper function: pass in a key and get value. null if not present
hashMap: HashMap<Text, Text>;
keys: [Text]; //list of query keys
};
anchor: Text; //an anchor if available(after the #;
};
headers: {
original: Array<(Text, Text)>;
get: (Text) -> ?[Text] //helper function: pass in a key and get values. null if not present
hashMap: HashMap<Text, [Text]>;
keys: [Text]; //list of header keys
};
body: ?{ //Get requests won't have a body
original: Blob
size: Nat; //size of the body
form: { //if the content-type is as specified at https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST, parse the form and populate the collection
get: (Text) -> ?[Text] //helper function: pass in a key and get value. null if not present
hashMap: HashMap<Text, [Text]>;
keys: [Text]; //list of form keys;
files: (Text) -> ?[Buffer<Nat8>]; //helper function returns the formdata as a byte array; null if the form entry does not exist
};
text: () -> Text; //converts the Blob to plain text
file: () -> ?Buffer<Nat8>; //if not formdata and only one file is provided it will be here.
bytes: (start, end) -> Buffer<Nat8>;//helper function: return the specified bytes from the blob.
};
};
This library is an opportunity to start a RegEx like library for motoko. RegEx is hard and big and complicated, so this is not a requirement, but if the bounty hunter wanted to dive into the basics of RegEx and explore how well/poorly motoko was going to be for RegEx it would be a bonus.
Prior art that may help in getting you started:
https://github.com/aramakme/aramakme_nft_auction/blob/f0ca7fb629814dc24a90ad84c7d024a49390e38b/main.mo#L2757 https://github.com/dfinity/motoko-base/blob/57c3bb724dfe36928d443f5a81446872bf646de9/src/Text.mo#L346
GitHub - tomijaga/http-parser.mo: HTTP Request Parser for Motoko
The bounty was generously funded by the community and the DFINITY Foundation Grant. If you would like to turbocharge this bounty you can seed additional donations of ICP to 860bd56f4c8a9d40f26462e51e2a4dd4e27cf0e1463372a1179df089695bfd63. ICDevs will match the bounty 1:1 for the first 20 ICP and then 0.25:1 after that. All donations will be tax deductible for US Citizens and Corporations. If you send a donation and need a donation receipt, please email the hash of your donation transaction, physical address, and name to donations@icdevs.org. More information about how you can contribute can be found at our donations page.