Postman Client
Postman client is an optional extension that can be added to your VS Code. The extension is an early version and lacks functionality compared with the full application. A collection imported into the application is visible in the extension.
The BaaS extension enables automatic authentication with the deployed version of the BaaS service. Of course, it can also be used to call locally running services.
Setup
There are three BaaS Settings that enable the automatic Postman authentication for the requests to the deployed BaaS Service. "Enable Session Provider Server" (enabled by default), "Session Provider Server Port" (default 50010), and "Session Provider Server Access Key" (redacted default ################################ )
Every full code example has a "postman-collection.json" file included to be imported into the Postman application client.
A minimal "postman-collection.json" is created with a new service.
For an existing service, a "postman-collection.json" can be created with the command "F1 - Baas: Create REST Client Collection File". This creates a new file from the template and overwrites any existing file.
The created minimal collection file contains named folders and a pre-request script with current settings for fetching the values from the Session Provider.
The script uses the "Enable Session Provider Server" and "Session Provider Server Port" to retrieve the session values.
The "Session Provider Server Access Key" setting value must match the one in the script file for the session values to be returned.
Clear the "Session Provider Server Access Key" setting to always return session values regardless of the access key in the script, or change the default value to increase security.
Requests
A request can be created using "Add request" under the three dots next to the new collection.
The URL used in the request looks differently depending on if you call a deployed service or a locally running service.
__Deployed__
_{{BAAS_IONAPI_BASE_URL}}/BaaSApi/{context in suite}/{lowercase manifest name}/{lowercase openapi name}/api/{api path}_
Example of a url using the default suite and a project named "myservice" with an openapi named "Test":
_{{BAAS_IONAPI_BASE_URL}}/BaaSApi/baasservices/myservice/test/api/v1/..._
__Local__
_http://localhost:7071/{lowercase openapi name}/api/{api path}_
Example of a url using the default suite and a project named "myservice" with an openapi named "Test":
_http://localhost:7071/test/api/v1/..._
Collections
Either install the application or use the postman web gui.
- Create a workspace.
- Click import and follow the instructions, for.example: filename "postman-collection.json".
Postman Pre-request Script
Add the following script in the "Pre-request Script" section of the collection in Postman. This automatically updates the BAAS_IONAPI_BASE_URL and BAAS_IONAPI_ACCESS_TOKEN variables for the current request. "Unresolved Variable" is by design, since it is set when the request is executed.
```
const accessKey = pm.globals.get('BAAS_ACCESS_KEY') ?? "################################";
const port = pm.globals.get('BAAS_PORT') ?? "50010";
pm.sendRequest(`http://localhost:${port}/values?accesskey=${accessKey}`, function (error, response) {
if (response.code == 200) {
_.map(response.json(), (value, key) => {
pm.variables.set(key, value);
});
} else {
console.error(error ?? response.text());
}
});
```
Postman Variables (optional)
For enhanced security, the access key and port can be changed. These settings can be configured from the "Environment quick look" button in Postman. They should match the values found in BaaS settings.
Default values _BAAS_ACCESS_KEY = ################################_ (see BaaS settings for actual default value) _BAAS_PORT = 50010_.
In BaaS settings (open with F1 - "BaaS: Open Settings").
BAAS_ACCESS_KEY is defined by "Rest Client Value Provider Server Accesskey" setting in section Authentication.
BAAS_PORT is defined by "Rest Client Value Provider Server Port" setting in section Authentication.
The content of the pre-request script is included in the collections provided for the Postman import in the BaaS example service projects. The sample services are available from Documentation>Code Examples>Complete projects in the online documentation.