-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RequestManager] 'body' should be a valid key in the request #8507
Comments
btw, while this "works" and is within your right to do (as extending this class and making it a service is fine as long as the public contract for async makeRequest(method, params, headers, useDatabase=true, context = {}) {
let host = '';
if (config.apiHost) {
host = config.apiHost.replace(/\/$/, ''); // remove the last slash
}
if (useDatabase === true) {
host += '/' + config.apiDatabase + '/';
}
let askHeaders = new Headers();
this.buildHeader(askHeaders);
const response = await this.request({
url: host,
headers: askHeaders,
method: 'POST',
body: JSON.stringify({ method: method, params: params}) // using `data` here sends the request without the body
});
// do something if needed
return response;
} you'll get better long-term utility out of a handler + util const JSONRPCHandler = {
request(context, next) {
if (context.request.op !== 'jsonrpc') return next(context.request);
const headers = context.request.headers?.clone() || new Headers();
headers.append('Content-type', 'application/json');
const body = JSON.stringify(context.request.data);
return next(Object.assign({}, context.request, { headers, body });
}
}
function buildJSONRPCRequest({ method, params, headers }, useDatabase=true) {
let host = '';
if (config.apiHost) {
host = config.apiHost.replace(/\/$/, ''); // remove the last slash
}
if (useDatabase === true) {
host += '/' + config.apiDatabase + '/';
}
return { url: host, op: 'jsonrpc', data: { method, params }, headers};
} then use it like this requestManager.request(
buildJSONRPCRequest({ method: 'some method', params: {} })
); The general guidance here is this:
There's a few limitations of the current state of canary that definitely in the way here, small things to tidy/fix up, but generally speaking this is the approach we're encouraging (and where our debug asserts are too aggressive right now and in the way we need to work on tuning them). |
Thanks a lot for the guidance. I'm mostly writing Python code and do server-side things, so much appreciated! |
What I discovered is that when using
For each request to the backend I generate a unique UID key (I'm going to use UUID) so that can be used as key in the Cache. |
I'm trying to get the
requestManager
working but walked straight into the problem that thebody
key is not a valid key. Below the very basic code.data
is a valid key that is somehow not send to the backend. Also https://developer.mozilla.org/en-US/docs/Web/API/Request namesbody
as a valid key. Adding a hack to make thebody
to be a valid key, everything works and I get the response back with the version of the backend.The text was updated successfully, but these errors were encountered: