Closed Unnoen closed 6 months ago
I've chosen to use IDs instead of names as they uniquely identify a request or folder, ensuring that renaming won't break the scripts. You don't need to copy ID from JSON state. You can drag and drop a request or folder into the script or variables editor to obtain its ID. The inlay hint displays the corresponding name of a folder or request within the scripts. However, I understand that this might not be convenient during code reviews, where only the ID is visible.
I'm leaning towards the solution where users will be able to define their own functions. Currently this can be done by defining a global function global.findRequestByName
in the pre-request script of the root folder like:
global.findRequestByName = (name) => {
const rootFolder = jc.findFolder("47473add")
return findRequestByNameInFolder(name, rootFolder)
}
function findRequestByNameInFolder(name, folder) {
return folder.requests.find(r => r.name === name) || folder.folders.reduce((acc, f) => {
return acc || findRequestByNameInFolder(name, f)
}, null)
}
However, this will only work in request and folder scripts, and won't work in test suites, because parent folder scripts are not executed for test suites.
But I plan to implement a dynamic variables feature, where besides the predefined functions users will be able to define their own functions. This will allow to define findRequestByName
function and use it in any script.
Starting from version 2024.2.0, the methods jc.runRequest
, jc.sendRequest
, jc.runFolder
, jc.runTestSuite
now accept a request or folder path relative to the project (the root collection) instead of an ID
Is your feature request related to a problem?
Currently, as far as I understand, the
jc.findFolder()
andjc.findRequest()
functions can only search by ID, even though the ID of these objects are not exposed anywhere and must be found by checking the JetClient state JSON.Describe the solution you'd like
Ideally, new methods would be created.
The ability to use {{variables}} in the strings without needing to call
jc.variables
etc. would be a very nice feature. Perhaps passing {{variables}} could be a boolean value? e.g.,jc.findFolderByName(folderName: string, parseVariables: boolean)
Used like:jc.findFolderByName("{{integrationFolder}}", true)
Finding folders:
findFolderById(idPrefix: string)
findFolder()
method, don't removefindFolder()
, to keep backwards compatibility, but having a dedicated method for finding by ID would help with understanding at a glance. (Perhaps mark the current method as@deprecated
?)findFolderByName(folderName: string)
jc.findFolderByName("My API")
findFolderByDescription(folderDescription: string)
jc.findFolderByDescription("Testing API")
Finding requests:
findRequestById(idPrefix: string)
findRequest()
method, don't removefindRequest()
, to keep backwards compatibility, but having a dedicated method for finding by ID would help with understanding at a glance. (Perhaps mark the current method as@deprecated
?)findRequestByName(requestName: string)
jc.findRequestByName("Login Client")
findRequestByDescription(requestDescription: string)
jc.findRequestByDescription("Posts client credentials")
findRequestByUrl(requestMethod: HttpMethod|string, requestUrl: string)
jc.findRequestByUrl(HttpMethod.POST, "{{clientUrl}}/login", true)
(This example uses the {{variable}} parse boolean)Additional context
No response