You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To perform an http request call the canister needs to expose two endpoints: http_request as a query method, and http_request_update as an update method. The http_request method needs to return an upgrade value of Some(true) and all other fields are ignored.
We already have tests for http_request so it is proposed that this canister's http_request method be hardcoded rather than arbitrary.
The generated canister may look like this:
import{Canister,HttpRequest,HttpResponse,nat8,None,Null,query,Some,update}from'azle';conststate: number=0;exportdefaultCanister({http_request: query([HttpRequest],HttpResponse(Null),()=>{return{status_code: 204,headers: [],body: newUint8Array(),streaming_strategy: None,upgrade: Some(true)};}),http_request_update: update([HttpRequest],HttpResponse(Null),(request)=>{constexpectations={};if(request!==expectations){thrownewError('The http request was different than expected');}return{status_code: 201,headers: [['content-type','text/plain'],['content-encoding','gzip']],body: Uint8Array.from([31,139,8,0,55,2,27,98,0,3,43,45,72,73,44,73,229,2,0,168,218,145,108,7,0,0,0]),streaming_strategy: None,upgrade: None};}),get_state: query([],nat8,()=>{returnstate;})});
Then we can hit the http_request endpoint with various http requests with different methods, urls, headers, and bodies, and then update can effect state changes...
So we also need a way to get the state changes back out... so we could use http_request and have it return the state... but then we'd have to control how it decides to do a query vs update... I think it's better to just leave http_request alone and instead have a second method for querying state.
So the test will be, when we make an arbitrary http request:
Does the body request param inside of http_request_update decode correctly?
To perform an http request call the canister needs to expose two endpoints:
http_request
as a query method, andhttp_request_update
as an update method. Thehttp_request
method needs to return anupgrade
value ofSome(true)
and all other fields are ignored.We already have tests for
http_request
so it is proposed that this canister'shttp_request
method be hardcoded rather than arbitrary.The generated canister may look like this:
Then we can hit the
http_request
endpoint with various http requests with different methods, urls, headers, and bodies, and then update can effect state changes...So we also need a way to get the state changes back out... so we could use http_request and have it return the state... but then we'd have to control how it decides to do a query vs update... I think it's better to just leave http_request alone and instead have a second method for querying state.
So the test will be, when we make an arbitrary http request:
http_request_update
decode correctly?So tests would look like:
Resources:
The text was updated successfully, but these errors were encountered: