Feature request: map appropriate HTTP request methods to update calls

I brought this up here but that thread has gotten long and there are multiple conversations happening:

I would like to request that appropriate HTTP request methods are mapped to update calls instead of query.

I think at least POST, PUT, PATCH, and DELETE would be a great start.

I could make a PR to agent-rs to do this but it would need the equivalent support in replicas.

Actually, the HTTP handling is done by the icx-proxy component in the agent-rs repo, which already is open source, so a feature request there is not inappropriate.

Turning POST into an update call is certainly a possibility. I think we have hesitated because maybe not every POST should be an update call? Imagine an image transcoding service – you probably upload the file with POST, but maybe still want the performance of a query call. Also, despite best intentions in the HTTP spec, in practice you might want state modification on GET as well in some cases.

So tying it to the method seems a bit too rigid.

In my prototype, a query call is done first, and but it can tell the proxy to upgrade to an update call, but it’s also not clear if that’s ideal.

If you don’t mind having an URL that is not *.ic0.app, at least for experimentation, you can run a patched icx-proxy on your own infrastructure, and use that. The HTTP handling sits nicely on top of the core IC, instead of being a feature you can’t extract.


This is great news. Since I’m going to do this anyway I’ll probably make a PR and then it can be debated there :grinning_face_with_smiling_eyes:

In one of my use cases I could possibly run a forked version but it would be a lot neater not to.

My plan was to make the mapping configurable but with some defaults that match the intentions of the HTTP spec.

That way, different instances of the proxy could be configured differently on start up. It could even be as granular as mapping a specific route to a certain call rather than the entire request method.

Could you help me understand how that would work? I thought an update call is the only way to modify state.

That’s what I mean with a image transcoding: You POST a .gif, it returns a .jpg, but doesn’t actually store anything. Not saying it’s a great example for an on-IC-app, but maybe still can serve as an example for a POST call that you want to get query-called.

I forked agent-rs and ran it locally, with the change I proposed at the top of this thread.

I encountered 2 problems:

  1. Without a query annotation on http_request, I get Replica Error (3): "IC0302: Canister rrkah-fqaaa-aaaaa-aaaaq-cai has no query method 'http_request'"

  2. When making an update call via http_request I get 500 Internal Server Error on the client and see WARN Internal Error during request: CertificateVerificationFailed on the server.

It looks like #1 would require a change to the replica code to allow http_request to have a shared annotation.

I haven’t been able to figure out #2 yet.

Re #1: I suggest that your fork uses a different method name (http_update_request). It can have the same implementation, but the system (rightfully) rejects query calls to methods that aren’t marked query.

The replica is not involved here, this is a higher level feature (e.g. you can tell that The Internet Computer Interface Specification :: Internet Computer doesn’t mention it).

Re #2: You probably have to call fetch_root_key in the right spot.

1 Like