Creating a query with environment variables in Paw

In the Paw application, if we create a query manually, we can call the context menu and select the environment variable.

In this case, the URL is as follows:

And it will be updated if I have to change the environment or variable.

I'm trying to improve an existing plugin (Blueprint Importer API), and I only figured out how to read from an environment variable.
I can only do something like this , and have been read from the environment variables.
httplocalhost8000

Trying to achieve something like the first image, but to no avail.
Is there an API available in the Paw app, or is it unavailable right now?

+4
source share
1 answer

Paw. , , .

, , , context.getEnvironmentDomainByName context.createEnvironmentDomain. .

getOrCreateEnvironmentDomain(name) {
    let env = this.context.getEnvironmentDomainByName(name)
    if (typeof env === 'undefined') {
        env = context.createEnvironmentDomain(name)
    }
    return env
}

, . . , EnvironmentDomain.

getOrCreateEnvironment(domain, name) {
    let env = domain.getEnvironmentByName(name)
    if (typeof env === 'undefined') {
        env = domain.createEnvironment(name)
    }
    return env
}

- , , , .

/* 
    uses:
        @getOrCreateEnvironmentDomain
        @getOrCreateEnvironment
*/
updateOrCreateEnvironmentVariable(domainName, envName, name, value) {
    let domain = this.getOrCreateEnvironmentDomain(domainName)
    let env = this.getOrCreateEnvironment(domain, envName)
    let varDict = {}

    varDict[name] = typeof value !== 'undefined' ? value: ''
    env.setVariablesValues(varDict)
    return domain.getVariableByName(name)
}

, . com.luckymarmot.EnvironmentVariableDynamicValue, environmentVariable, , .

...
let envVariable = this.updateOrCreateEnvironmentVariable('Server', 'api-blueprint', 'protocol', 'https')
let dv = new DynamicValue(
    'com.luckymarmot.EnvironmentVariableDynamicValue',
    {
        environmentVariable: envVariable.id
    }
)
/* use the Dynamic Value like any other */
...
+3

Source: https://habr.com/ru/post/1654960/


All Articles