Skip to content

IC-128: First iteration of serving assets#9

Merged
dsarlis merged 1 commit into
mainfrom
dimitris/serve-assets
Apr 12, 2021
Merged

IC-128: First iteration of serving assets#9
dsarlis merged 1 commit into
mainfrom
dimitris/serve-assets

Conversation

@dsarlis
Copy link
Copy Markdown
Contributor

@dsarlis dsarlis commented Apr 12, 2021

This adds a very first implementation of serving assets from the IdP canister. I'm using two hard-coded assets for now to be able to implement the basic pieces of the interface. It basically initializes a map of assets during canister_init and then exposes the http_request query function required for the HTTP gateway to ask for assets.

Work left for future PRs:

  • This does not include the StreamingStrategy yet in the interface (see here for what's a StreamingStrategy), I need to figure out how to do that in Rust in a way that Candid understands.
  • Assets should be dynamically set during canister_init, likely as an input argument.

Testing

To install the canister locally:

cd idp_service/src
dfx start --background
dfx canister create idp_service
dfx build idp_service
dfx canister install idp_service

Then you can ask for an asset:

dfx canister call idp_service http_request '(record {method="GET"; url="/sample-asset.txt"; headers=vec {}; body=vec{};})'
(
  record {
    1_092_319_906 = blob "This is a sample asset!\0a";
    1_661_489_734 = vec {};
    3_475_804_314 = 200;
  },
)

If an asset does not exist:

dfx canister call idp_service http_request '(record {method="GET"; url="/where-is-my-asset.txt"; headers=vec {}; body=vec{};})'
(
  record {
    1_092_319_906 = blob "Asset /where-is-my-asset.txt not found.";
    1_661_489_734 = vec {};
    3_475_804_314 = 404;
  },
)

@dsarlis dsarlis force-pushed the dimitris/serve-assets branch from 80b10b7 to bb21a07 Compare April 12, 2021 10:58
@dsarlis dsarlis merged commit be4f9c4 into main Apr 12, 2021
@dsarlis dsarlis deleted the dimitris/serve-assets branch April 12, 2021 12:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant