Open rsaunders100 opened 3 years ago
Hi @rsaunders100, we'd not introduce the "Request Body Matching" because it could make the UI more complicated.
To resolve it, I'd highly suggest using ReWrite. Here is an example to solve your cases:
// Import file from More Button -> Import JSON or Other files
const file = require("@users/B02D96D5.default_message_32E64A5B.json");
function onRequest(context, url, request) {
// 1. Extract the name from Request Body
// request.body is a JSON, so you can get whatever you want
var queryName = request.body["name"]
// 2. Save to sharedState
sharedState.queryName = queryName
// Done
return request;
}
function onResponse(context, url, request, response) {
// 3. Check if it's the request we need to map
if (sharedState.queryName == "getUser") {
// 4. Import the local file by Action Button -> Import
// Get the local JSON file and set it as a body (like Map Local)
response.headers["Content-Type"] = "application/json";
response.body = file;
// Or change header, status code, body like Breakpoint Tool
// Example: https://docs.proxyman.io/scripting/snippet-code#2-common-on-request-and-response
}
// Done
return response;
}
Thanks! Very helpful.
Is the sharedState
variable specific to the request response pair? Or is it global for all requests?
Yes, it's only available in this request-response pair (not global variable for all requests). You can read more at https://docs.proxyman.io/scripting/environment-variables @rsaunders100
Proxyman version? (Ex. Proxyman 1.4.3)
Version 2.16.1 (21610)
We have a universal endpoint, the request body changes not the URL so there is no way to filter on a particular request for rewrite or a breakpoint.