[GH-ISSUE #946] Add "Don’t wait for Response" (Mock API) for scripts #941

Open
opened 2026-03-03 19:23:12 +03:00 by kerem · 2 comments
Owner

Originally created by @mprice-banno on GitHub (Jul 29, 2021).
Original GitHub issue: https://github.com/ProxymanApp/Proxyman/issues/946

Originally assigned to: @NghiaTranUIT on GitHub.

Proxyman version? (Ex. Proxyman 1.4.3)

2.30.0 (23000)

macOS Version? (Ex. mac 10.14)

11.4

Issue

Currently it is not possible to use a mapped response, for example map to local, and then modify that response based on the request. The usage example is updating a JWT authentication token that is in the local mapped response, but that has expired and can be obtained from the request.

Feature request to add "Don't wait for response" to the scripting configurations for an endpoint. This would allow users to create a response through function onResponse() without having to wait for the server to actually respond. This would be useful when mocking an endpoint that has not been deployed yet, or to speed up testing on a slow endpoint, and still allow the user to make changes to the response based on anything from the request.

Screenshots (optional)

Originally created by @mprice-banno on GitHub (Jul 29, 2021). Original GitHub issue: https://github.com/ProxymanApp/Proxyman/issues/946 Originally assigned to: @NghiaTranUIT on GitHub. ### Proxyman version? (Ex. Proxyman 1.4.3) 2.30.0 (23000) ### macOS Version? (Ex. mac 10.14) 11.4 ### Issue Currently it is not possible to use a mapped response, for example map to local, and then modify that response based on the request. The usage example is updating a JWT authentication token that is in the local mapped response, but that has expired and can be obtained from the request. Feature request to add "Don't wait for response" to the scripting configurations for an endpoint. This would allow users to create a response through `function onResponse()` without having to wait for the server to actually respond. This would be useful when mocking an endpoint that has not been deployed yet, or to speed up testing on a slow endpoint, and still allow the user to make changes to the response based on anything from the request. ### Screenshots (optional)
Author
Owner

@NghiaTranUIT commented on GitHub (Aug 13, 2021):

Hey @mprice-banno please check out this beta build: https://proxyman.s3.us-east-2.amazonaws.com/beta/Proxyman_2.31.0_Scripting_Mock_APIs.dmg

From now, you can use Scripting as a Mock API. The request would not go to the server, it will return intermediately 👍

To enable it, please select your Script -> Click on Option button -> Check Use onResponse() as Mock API.

Then defining your response.


/// This func is called if the Response Checkbox is Enabled
/// You can manipulate the Response Data here before it goes to the client
/// e.g. Add/Update/Remove: headers, statusCode, comment, color and body (json, plain-text, base64 encoded string)
///
/// Use console.log(response) to see all available fields
///
function onResponse(context, url, request, response) {

  // Init new body
  var body = {};
  body["new-key"] = "Proxyman";
  response.body = body;

  // Or map from a file
  // response.bodyFilePath = "~/Desktop/myfile.json"
  
  // Done
  return response;
}

Documentation: https://docs.proxyman.io/scripting/script#8-use-scripting-as-a-mock-api


Please let me know if it works for you 😄

<!-- gh-comment-id:898470661 --> @NghiaTranUIT commented on GitHub (Aug 13, 2021): Hey @mprice-banno please check out this beta build: https://proxyman.s3.us-east-2.amazonaws.com/beta/Proxyman_2.31.0_Scripting_Mock_APIs.dmg From now, you can use Scripting as a Mock API. The request would not go to the server, it will return intermediately 👍 To enable it, please select your Script -> Click on Option button -> Check Use onResponse() as Mock API. Then defining your response. ```js /// This func is called if the Response Checkbox is Enabled /// You can manipulate the Response Data here before it goes to the client /// e.g. Add/Update/Remove: headers, statusCode, comment, color and body (json, plain-text, base64 encoded string) /// /// Use console.log(response) to see all available fields /// function onResponse(context, url, request, response) { // Init new body var body = {}; body["new-key"] = "Proxyman"; response.body = body; // Or map from a file // response.bodyFilePath = "~/Desktop/myfile.json" // Done return response; } ``` Documentation: https://docs.proxyman.io/scripting/script#8-use-scripting-as-a-mock-api --------------- Please let me know if it works for you 😄
Author
Owner

@mprice-banno commented on GitHub (Aug 19, 2021):

@NghiaTranUIT Thanks!! I've only had a chance to briefly play with this so far, but it's working for me so far! Great idea having the "empty" response include the info message:

{ "httpVersion": "HTTP/1.1", "statusCode": 200, "statusPhrase": "OK", "body": { "comment": "To disable it: Select your script -> More button -> Uncheck Use onResponse() as Mock API", "scriptName": "Untitled", "description": "It's a Mock Response template. You can modify the Response data on onResponse() function." }, "rawBody": "{\n \"description\": \"It's a Mock Response template. You can modify the Response data on onResponse() function.\",\n \"comment\": \"To disable it: Select your script -> More button -> Uncheck Use onResponse() as Mock API\",\n \"scriptName\": \"Untitled\"\n}", "headers": { "Content-Type": "application/json" } }

<!-- gh-comment-id:902268714 --> @mprice-banno commented on GitHub (Aug 19, 2021): @NghiaTranUIT Thanks!! I've only had a chance to briefly play with this so far, but it's working for me so far! Great idea having the "empty" response include the info message: `{ "httpVersion": "HTTP/1.1", "statusCode": 200, "statusPhrase": "OK", "body": { "comment": "To disable it: Select your script -> More button -> Uncheck Use onResponse() as Mock API", "scriptName": "Untitled", "description": "It's a Mock Response template. You can modify the Response data on onResponse() function." }, "rawBody": "{\n \"description\": \"It's a Mock Response template. You can modify the Response data on onResponse() function.\",\n \"comment\": \"To disable it: Select your script -> More button -> Uncheck Use onResponse() as Mock API\",\n \"scriptName\": \"Untitled\"\n}", "headers": { "Content-Type": "application/json" } } `
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/Proxyman#941
No description provided.