### Start Node.js Application Locally Source: https://github.com/apigee/api-platform-samples/blob/master/doc-samples/hosted-targets/node-hosted-hello/README.md Run this command to start the Node.js application on your local machine for testing. Ensure Node.js is installed. ```bash PORT=8081 node apiproxy/resources/hosted/index.js ``` -------------------------------- ### Install Dependencies Source: https://github.com/apigee/api-platform-samples/blob/master/doc-samples/hosted-targets/node-hosted-express/README.md Install Node.js dependencies for the hosted target application. Navigate to the hosted resources directory before running this command. ```bash cd apiproxy/resources/hosted npm install ``` -------------------------------- ### Example API Request Source: https://github.com/apigee/api-platform-samples/blob/master/sample-proxies/apikey/README.md An example of an API request that includes an API key as a query parameter. ```bash curl "http://myorg-test.apigee.net/mocktarget_key/json?apikey=abc123" ``` -------------------------------- ### Example GraphQL Query Source: https://github.com/apigee/api-platform-samples/blob/master/sample-proxies/graphql-sample/README.md This is an example of a GraphQL query that accesses resort data. ```graphql query { resorts { id, name } } ``` -------------------------------- ### Example API Call Source: https://github.com/apigee/api-platform-samples/blob/master/sample-proxies/outbound-oauth/README.md This is an example of how to call the API proxy to search for tweets in a specific language. ```bash curl -v "http://demo-prod.apigee.net/outbound-oauth/search.json?lang=es&q=bicycle" ``` -------------------------------- ### Start Node.js Application Locally Source: https://github.com/apigee/api-platform-samples/blob/master/doc-samples/hosted-targets/node-hosted-express/README.md Start the Node.js Express application locally. Set the PORT environment variable to specify the port for the application. ```bash PORT=8081 node index.js ``` -------------------------------- ### Environment Setup Script Source: https://github.com/apigee/api-platform-samples/blob/master/doc-samples/javascript-mashup-cookbook/README.md This script is used to set up environment variables for the sample project. Update the file with your specific environment details. ```bash #!/bin/bash # # Copyright (c) 2015 Apigee Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # This script sets up environment variables for the sample project. # Update the following variables with your environment details. # Set your Apigee organization name export ORG_NAME="your-organization-name" # Set the environment name (e.g., test, prod) export ENV_NAME="test" # Set the API proxy name export API_PROXY_NAME="altitude2" # Set the base path for the API proxy export BASE_PATH="/v1/${API_PROXY_NAME}" # Set the username and password for Apigee login export APIGEE_USERNAME="your-email@example.com" export APIGEE_PASSWORD="your-password" # Set the API key for external services (if required) # export EXTERNAL_API_KEY="your-external-api-key" # Set the endpoint for the Google Geocoding API # export GEOCODING_API_ENDPOINT="https://maps.googleapis.com/maps/api/geocode/json" # Set the endpoint for the Google Elevation API # export ELEVATION_API_ENDPOINT="https://maps.googleapis.com/maps/api/elevation/json" # You can add other environment-specific configurations here echo "Environment variables set for Apigee sample project." ``` -------------------------------- ### Successful Deployment Output Example Source: https://github.com/apigee/api-platform-samples/blob/master/README.md This output indicates a successful deployment of an API proxy. Verify that the 'State' is 'deployed' to confirm readiness. ```shell Imported new proxy version 3 Undeploying revision 2 in same environment and path: Environment: test Revision: 3 BasePath = / State: error If 'State: deployed', then your API Proxy is ready to be invoked. Run 'invoke.sh' ``` -------------------------------- ### Example cURL Command Source: https://github.com/apigee/api-platform-samples/blob/master/sample-proxies/base64encoder/README.md Shows how to invoke the API proxy with username and password query parameters for base64 encoding. ```bash curl -i "https://$org-$env.$api_domain/base64encoder?username=MyUserName&password=MyPassword" ``` -------------------------------- ### Access Token Response Example Source: https://github.com/apigee/api-platform-samples/blob/master/sample-proxies/oauth-client-credentials/README.md This is an example of the JSON response received from Apigee Edge after a successful client credentials grant type request. It includes details like the access token, expiration, client ID, and associated API products. ```json { "issued_at" : "1416157639014", "application_name" : "e49ef95f-6d32-4062-ac9a-3beea62ca922", "scope" : "", "status" : "approved", "api_product_list" : "[Test App product]", "expires_in" : "3599", "developer.email" : "testdev@example.com", "organization_id" : "0", "token_type" : "BearerToken", "client_id" : "kWocGgKENrdWRT0jq4l0F0ACnPAQsD3", "access_token" : "WNSnwquKualbgnGeAK0EXGqzO3A", "organization_name" : "example", "refresh_token_expires_in" : "0", "refresh_count" : "0" } ``` -------------------------------- ### XML Response Example Source: https://github.com/apigee/api-platform-samples/blob/master/sample-proxies/xmltojson/README.md The default XML format returned by the backend service before transformation. ```xml San Jose John Doe CA ``` -------------------------------- ### Submit Task and Handle Callback Source: https://github.com/apigee/api-platform-samples/blob/master/docs/javadocs-javacallout/com/apigee/flow/execution/Callback.html This example demonstrates submitting a task asynchronously and defining a callback to be executed upon its completion. The task and callback should be independent of the message and execution contexts. ```java public class SubmitTaskAndContinueCallbackHandling implements Execution { private static final Logger logger = LoggerFactory.getLogger("SubmitTaskAndContinueCallbackHandling"); public ExecutionResult execute(final MessageContext messageContext, final ExecutionContext executionContext) { executionContext.submitTask(new Task(), new CallbackTask(), "handback"); return ExecutionResult.SUCCESS; } private static class Task implements Runnable { public void run() { // Perform task unrelated to the proxy flow, such as sending data to // an analytics server. } } private static class CallbackTask implements Callback { public void callback(Runnable task, Object handback) { // Log completion results } } } ``` -------------------------------- ### Deploy Proxy to Apigee Source: https://github.com/apigee/api-platform-samples/blob/master/doc-samples/hosted-targets/node-hosted-express/README.md Deploy the Node.js hosted target proxy to Apigee using apigeetool. Ensure you have apigeetool and get_token installed and configured. ```bash get_token && apigeetool deployproxy \ -o \ -e \ --json \ --token "$(< ~/.sso-cli/valid_token.dat)" \ --api node-hosted-express \ --directory . ``` -------------------------------- ### Deploy API Proxy Command Source: https://github.com/apigee/api-platform-samples/blob/master/tools/README.md Use this command to import and deploy an API proxy from your local machine to an Apigee environment. Ensure Python is installed and you have an Apigee account. ```bash deploy.py -n {apiName} -u {myname:mypass} -o {myorg} -e {environment} -p {basePath} -d {path to /apiproxy directory} ``` -------------------------------- ### Deploy Node.js Hosted Target Proxy Source: https://github.com/apigee/api-platform-samples/blob/master/doc-samples/hosted-targets/node-hosted-custom-deps/README.md Deploys a Node.js proxy with bundled dependencies to Apigee using apigeetool. Ensure apigeetool and get_token are installed. ```bash get_token && apigeetool deployhostedtarget \ -o \ -e \ -n hosted-hello-conversion \ -d ./myapp/ \ -b hosted-hello-conversion \ --bundled-dependencies \ --json \ --token "$(< ~/.sso-cli/valid_token.dat)" ``` -------------------------------- ### Execute Sample API Proxy Invocation Script Source: https://github.com/apigee/api-platform-samples/blob/master/README.md Run the invoke.sh script to send a sample HTTP request to the deployed API proxy. This script typically uses curl and may perform additional setup tasks. ```bash ./invoke.sh ``` -------------------------------- ### Response Header with Encoded Credentials Source: https://github.com/apigee/api-platform-samples/blob/master/sample-proxies/base64encoder/README.md An example of the HTTP response, highlighting the custom header containing the base64 encoded credentials. ```http HTTP/1.1 200 OK User-Agent: curl/7.37.1 Host: docs-test.apigee.net Accept: */* X-Encoded-Credentials: Basic TXlVc2VyTmFtZTpNeVBhc3N3b3Jk Content-Length: 0 Connection: keep-alive ``` -------------------------------- ### Deploy Node.js Proxy to Apigee Source: https://github.com/apigee/api-platform-samples/blob/master/doc-samples/hosted-targets/node-hosted-hello/README.md Deploy the Node.js hosted target proxy to your Apigee organization and environment. Ensure apigeetool and get_token are installed and configured. ```bash get_token && apigeetool deployproxy \ -o \ -e \ --json \ --token "$(< ~/.sso-cli/valid_token.dat)" \ --api node-hosted-hello \ --directory . ``` -------------------------------- ### Sample Proxy Response Source: https://github.com/apigee/api-platform-samples/blob/master/sample-proxies/access-entity/README.md This is an example of the HTTP response received when invoking the sample proxy. It includes a custom header 'X-Developer-email' with the dynamically extracted developer email. ```http HTTP/1.1 200 OK User-Agent: curl/7.37.1 Host: docs-test.apigee.net Accept: */* X-Developer-email: tesla@weathersample.com Content-Length: 0 Connection: keep-alive ``` -------------------------------- ### Example cURL Command Source: https://github.com/apigee/api-platform-samples/blob/master/sample-proxies/conditional-policy/README.md Use this cURL command to invoke the API proxy and trigger the conditional Python script by setting the 'responsetime' header to 'true'. ```bash curl -i -H "responsetime:true" "http://$org-$env.$api_domain/v1/timer" ``` -------------------------------- ### Get Apigee Environments Source: https://github.com/apigee/api-platform-samples/blob/master/tools/README.md Retrieve a list of available environments for your Apigee organization using curl. Replace 'myname:mypass' with your credentials and '{org_name}' with your organization name. ```bash curl -u myname:mypass https://api.enterprise.apigee.com/v1/o/{org_name}/environments/ ``` -------------------------------- ### Key-Value Map Operations Test Source: https://github.com/apigee/api-platform-samples/blob/master/perf-proxies/README.md Tests basic Key-Value Map (KVM) operations, including getting and putting data. ```bash curl -v 'https://YOUR_ENV_GROUP_HOSTNAME/v1/perf?test=get-put-kvm' ``` -------------------------------- ### Conditional Python Script Execution Source: https://github.com/apigee/api-platform-samples/blob/master/sample-proxies/conditional-policy/README.md This example shows the response headers when the 'responsetime' header is set to 'true', indicating the Python script executed and populated custom metrics. ```http HTTP/1.1 200 OK Access-Control-Allow-Origin: * Content-Type: text/plain; charset=utf-8 Date: Thu, 03 Nov 2016 13:42:18 GMT ETag: W/"d-GHB1ZrJKk/wdVTdB/jgBsw" Server: Apigee Router X-Apigee-end-time: Thu, 3 Nov 2016 13:42:18 UTC X-Apigee-end-timestamp: 1478180538275 X-Apigee-start-time: Thu, 3 Nov 2016 13:42:18 UTC X-Apigee-start-timestamp: 1478180538088 X-Apigee-target: http://mocktarget.apigee.net X-Apigee-target-responseTime: 187 X-Powered-By: Apigee Content-Length: 13 Connection: keep-alive ``` -------------------------------- ### Set Message Headers and Content Source: https://github.com/apigee/api-platform-samples/blob/master/docs/javadocs-javacallout/com/apigee/flow/message/Message.html This example demonstrates how to set custom headers and the content of a message using the Message interface within an Apigee Java policy. It shows how to access the Message object from the MessageContext and call methods like setHeader and setContent. Note that this code executes in an IO thread. ```Java public class JavaSimpleBlocking implements Execution { public ExecutionResult execute(MessageContext messageContext, ExecutionContext executionContext) { try { // Call methods on the Message object associated with the message context. messageContext.getMessage().setHeader("X-Header-Thread", Thread.currentThread().getName()); // executes in IO thread messageContext.getMessage().setHeader("X-Header_Foo", "Bar"); messageContext.getMessage().setContent("Hello, World!"); return ExecutionResult.SUCCESS; } catch (Exception e) { return ExecutionResult.ABORT; } } } ``` -------------------------------- ### Constructing ExecutionResult with Action.ABORT Source: https://github.com/apigee/api-platform-samples/blob/master/docs/javadocs-javacallout/com/apigee/flow/execution/Action.html This example demonstrates how to use the Action.ABORT constant to create an ExecutionResult object when an exception occurs. It sets a custom error message and adds an error response header. ```Java public class JavaError implements Execution { public ExecutionResult execute(MessageContext messageContext, ExecutionContext executionContext) { try { // Code that may throw an error. return ExecutionResult.SUCCESS; } catch (RuntimeException ex) { ExecutionResult executionResult = new ExecutionResult(false, Action.ABORT); //--Returns custom error message and header executionResult.setErrorResponse(ex.getMessage()); executionResult.addErrorResponseHeader("ExceptionClass", ex.getClass().getName()); return executionResult; } } } ``` -------------------------------- ### Example API Response with Custom Headers and JSON Data Source: https://github.com/apigee/api-platform-samples/blob/master/doc-samples/javascript-cookbook/README.md This output shows the custom headers added by the JavaScript policy and the resulting JSON payload. It illustrates the dynamic modification of API responses. ```text < X-Apigee-Demo-Target: default < X-Apigee-Demo-ApiProxyName: simple-javascript < X-Apigee-Demo-ProxyName: default < X-Apigee-Demo-ProxyBasePath: /javascript-cookbook < X-Apigee-Demo-ProxyPathSuffix: /xml < X-Apigee-Demo-ProxyUrl: http://rrt330ea.us-ea.4.apigee.com/javascript-cookbook/xml < Server: Apigee Router < * Connection #0 to host artomatic-test.apigee.net left intact {"city":"San Jose","state":"CA"} ``` -------------------------------- ### Deployment Script Source: https://github.com/apigee/api-platform-samples/blob/master/sample-proxies/conditional-policy/README.md Run this script to deploy the sample API proxy. Ensure you have the necessary Apigee Edge environment configured. ```bash $ sh deploy.sh ``` -------------------------------- ### Navigate to Deployment Directory Source: https://github.com/apigee/api-platform-samples/blob/master/doc-samples/hosted-targets/node-hosted-express/README.md Return to the root directory of the project for deployment. ```bash cd ../../.. ``` -------------------------------- ### Provision Webserver App Script Source: https://github.com/apigee/api-platform-samples/blob/master/sample-proxies/oauth-advanced/README.md Execute the provisioning script with necessary credentials to create entities on Apigee Edge and obtain consumer keys. ```bash ./provision-webserver.sh username password orgName environment https://your-ms-url.com ``` -------------------------------- ### Example JSON Response Payload Source: https://github.com/apigee/api-platform-samples/blob/master/learn-edge/extract-json-payload-2/README.md This is an example of a JSON response payload that the policy will process. It's an array of objects, each containing 'name' and 'region' properties. ```json [ { "name" : "pod1", "region" : "us-east-1" }, { "name" : "pod2", "region" : "us-west-2" } ] ``` -------------------------------- ### Deploy GraphQL Sample Proxy with Maven Source: https://github.com/apigee/api-platform-samples/blob/master/sample-proxies/graphql-sample/README.md Deploys both graphql-config and graphql-proxy modules. Ensure you are in the 'graphql-smp' directory. Replace placeholders with your Apigee organization details. ```bash cd graphql-smp mvn install -Ptest -Dorg= -Denv= -Dusername= -Dpassword= ``` -------------------------------- ### getHeaders Source: https://github.com/apigee/api-platform-samples/blob/master/docs/javadocs-javacallout/com/apigee/flow/message/Message.html Gets all the values of a multivalued header. ```APIDOC ## getHeaders ### Description Gets all the values of a multivalued header. ### Method ```java List getHeaders(String headerName) ``` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters * **headerName** (String) - Required - The name of the header to retrieve. ### Request Example ```java List acceptValues = message.getHeaders("Accept"); ``` ### Response #### Success Response (List) The set of values associated with the header. #### Response Example ```java ["application/json", "text/plain"] ``` ``` -------------------------------- ### Deploy Sample Proxy Source: https://github.com/apigee/api-platform-samples/blob/master/sample-proxies/access-entity/README.md This command deploys the sample API proxy to your Apigee Edge environment. ```shell sh deploy.sh ``` -------------------------------- ### getHeadersAsObject Source: https://github.com/apigee/api-platform-samples/blob/master/docs/javadocs-javacallout/com/apigee/flow/message/Message.html Gets an object representation of the header values. ```APIDOC ## getHeadersAsObject ### Description Gets an object representation of the header values. ### Method ```java Object getHeadersAsObject(String headerName) ``` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters * **headerName** (String) - Required - The name of the multivalued header to retrieve. ### Request Example ```java Object headerObject = message.getHeadersAsObject("Accept"); ``` ### Response #### Success Response (Object) An object representation of the header values. #### Response Example ```java // Example response depends on the actual object representation ``` ``` -------------------------------- ### Deploy Script Source: https://github.com/apigee/api-platform-samples/blob/master/doc-samples/javascript-mashup-cookbook/README.md This script deploys the sample API proxy project to your Apigee environment. It requires environment variables to be set beforehand. ```bash #!/bin/bash # # Copyright (c) 2015 Apigee Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # This script deploys the sample API proxy project to your Apigee environment. # Source the environment variables script source ./setenv.sh # Check if required environment variables are set if [ -z "$ORG_NAME" ] || [ -z "$ENV_NAME" ] || [ -z "$API_PROXY_NAME" ] || [ -z "$APIGEE_USERNAME" ] || [ -z "$APIGEE_PASSWORD" ]; then echo "Error: One or more required environment variables are not set." echo "Please update and source the setenv.sh script." exit 1 fi # Deploy the API proxy using apigeetool # Ensure you have apigeetool installed: npm install -g apigeetool echo "Deploying API proxy '$API_PROXY_NAME' to environment '$ENV_NAME' in organization '$ORG_NAME'..." apigeetool deploy --username "$APIGEE_USERNAME" --password "$APIGEE_PASSWORD" --organization "$ORG_NAME" --environment "$ENV_NAME" --api "$API_PROXY_NAME" --basepath "$BASE_PATH" if [ $? -eq 0 ]; then echo "API proxy deployed successfully." echo "You can now invoke the API using:" echo "curl \"http://$ORG_NAME-$ENV_NAME.apigee.net$BASE_PATH?country=us&postalcode=08008\"" else echo "Error deploying API proxy." exit 1 fi ``` -------------------------------- ### getVariableAsString Source: https://github.com/apigee/api-platform-samples/blob/master/docs/javadocs-javacallout/com/apigee/flow/message/MessageContext.html Gets a named flow variable as a String. ```APIDOC ## getVariableAsString ### Description This is similar to `getVariable(String name)` except that the output will always be a String. For non-String objects, String.valueof would be used to compute the String value for the object. ### Method GET (Implicit) ### Endpoint N/A (SDK method) ### Parameters #### Query Parameters - **name** (String) - Required - The name of the flow variable. ### Returns - **String** - The string value of the flow variable. ``` -------------------------------- ### Invoke OAuth Login App Sample Source: https://github.com/apigee/api-platform-samples/blob/master/sample-proxies/oauth-login-app/README.md Run this script to test the deployed sample project. This will initiate the OAuth flow. ```shell sh invoke.sh ``` -------------------------------- ### Execute Deployment Script Source: https://github.com/apigee/api-platform-samples/blob/master/README.md Run the deploy script to deploy a sample API proxy. This script will undeploy any existing revision before deploying a new one. ```shell ./deploy.sh ``` -------------------------------- ### getHeader (index) Source: https://github.com/apigee/api-platform-samples/blob/master/docs/javadocs-javacallout/com/apigee/flow/message/Message.html Gets a particular value of a multivalued header. ```APIDOC ## getHeader ### Description Gets a particular value of a multivalued header. ### Method ```java String getHeader(String headerName, int index) ``` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters * **headerName** (String) - Required - The name of the multivalued header. * **index** (int) - Required - The index of the value to get. Index starts at 1. ### Request Example ```java String secondAcceptValue = message.getHeader("Accept", 2); ``` ### Response #### Success Response (String) The value of the multivalued header at the specified index number. #### Response Example ```java "text/plain" ``` ``` -------------------------------- ### getVariable Source: https://github.com/apigee/api-platform-samples/blob/master/docs/javadocs-javacallout/com/apigee/flow/message/MessageContext.html Gets a named flow variable from the proxy flow. ```APIDOC ## getVariable ### Description Gets a named flow variable from the proxy flow in Edge. ### Method GET (Implicit) ### Endpoint N/A (SDK method) ### Parameters #### Query Parameters - **name** (String) - Required - The name of the flow variable. ### Returns - **T** - The value of the flow variable. ``` -------------------------------- ### getQueryParam Source: https://github.com/apigee/api-platform-samples/blob/master/docs/javadocs-javacallout/com/apigee/flow/message/Message.html Gets a specific value from a multivalued query parameter by its index. ```APIDOC ## getQueryParam ### Description Gets a particular value of a multivalued query parameter. ### Method GET (implied) ### Endpoint N/A (SDK method) ### Parameters #### Path Parameters None #### Query Parameters * **queryParamName** (string) - Required - The name of the multivalued query parameter. * **index** (int) - Required - The index of the value to get. Index starts with 1. ### Request Example None (SDK method) ### Response #### Success Response * **string** - The value of the multivalued query parameter at the specified index. #### Response Example None (SDK method) ``` -------------------------------- ### Run Apigee Organization Snapshot Tool Source: https://github.com/apigee/api-platform-samples/blob/master/tools/org-snapshot/README.md This command-line usage demonstrates how to run the Apigee Organization Snapshot Tool. All parameters are optional and will prompt the user if not provided. ```bash ./apigee-getorg.sh -e {admin-email} -s {mgmtserver} -o {org-name} -d {bundle-loc} ``` -------------------------------- ### getQueryParamValuesCount(String) Source: https://github.com/apigee/api-platform-samples/wiki/javadocs-javacallout/index-all.html Gets the number of values for a specific query parameter. ```APIDOC ## getQueryParamValuesCount(String name) ### Description Gets the number of values for a specific query parameter. ### Method N/A (Interface Method) ### Endpoint N/A ### Parameters - **name** (String) - Required - The name of the query parameter. ### Response - **int**: The number of values for the query parameter. ``` -------------------------------- ### getQueryParamValuesCount Source: https://github.com/apigee/api-platform-samples/wiki/javadocs-javacallout/com/apigee/flow/message/Message.html Gets the number of values for a specific multi-valued query parameter. ```APIDOC ## getQueryParamValuesCount ### Description Gets the number of values for a specific multi-valued query parameter. ### Method Signature `int getQueryParamValuesCount(java.lang.String queryParamName)` ### Parameters #### Path Parameters - **queryParamName** (string) - The name of the query parameter. ### Returns - **int** - The number of values for the specified query parameter. ``` -------------------------------- ### getHeadersAsString Source: https://github.com/apigee/api-platform-samples/blob/master/docs/javadocs-javacallout/com/apigee/flow/message/Message.html Gets all the values of a multivalued header as a string, concatenated with a transport-specific separator. ```APIDOC ## getHeadersAsString ### Description Gets all the values of a multivalued header as string. The string is constructed using the transport specific separator. ### Method ```java String getHeadersAsString(String headerName) ``` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters * **headerName** (String) - Required - The name of the multivalued header to retrieve. ### Request Example ```java String acceptHeader = message.getHeadersAsString("Accept"); ``` ### Response #### Success Response (String) The set of values associated with the header, as a single string. #### Response Example ```java "application/json, text/plain" ``` ``` -------------------------------- ### getQueryParamsCount Source: https://github.com/apigee/api-platform-samples/wiki/javadocs-javacallout/com/apigee/flow/message/Message.html Gets the total number of query parameters in the message, applicable for requests. ```APIDOC ## getQueryParamsCount ### Description Gets the total number of query parameters if the message is a request. ### Method Signature `int getQueryParamsCount()` ### Returns - **int** - The number of query parameters. ``` -------------------------------- ### JSON Response Example Source: https://github.com/apigee/api-platform-samples/blob/master/sample-proxies/xmltojson/README.md The JSON format of the data after being processed by the XML to JSON policy. ```json {"root":{"city":"San Jose","firstName":"John","lastName":"Doe","state":"CA"}} ``` -------------------------------- ### getHeader Source: https://github.com/apigee/api-platform-samples/blob/master/docs/javadocs-javacallout/com/apigee/flow/message/Message.html Gets the value of the specified header. If the header has multiple values, this method retrieves the first one. ```APIDOC ## getHeader ### Description Gets the value of the specified header. Equivalent to `getHeader(headerName, 1)`. ### Method ```java String getHeader(String headerName) ``` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters * **headerName** (String) - Required - The name of the header to retrieve. ### Request Example ```java String contentType = message.getHeader("Content-Type"); ``` ### Response #### Success Response (String) The value associated with the header name. If the header has multiple values, this method retrieves the first one. #### Response Example ```java "application/json" ``` ``` -------------------------------- ### Deploy Samplet Proxy Source: https://github.com/apigee/api-platform-samples/blob/master/samplets/README.md This command changes the file permissions to allow execution of the deploy script. ```bash chmod 755 deploy.sh ./deploy.sh ``` -------------------------------- ### Configure and Run Mocha Tests Source: https://github.com/apigee/api-platform-samples/blob/master/default-proxies/helloworld/test/test.html Sets up the Mocha testing environment, checks for leaks, defines global variables, and runs the tests. Use this for basic Mocha test execution. ```javascript mocha.setup('bdd'); mocha.checkLeaks(); mocha.globals(['jQuery']); mocha.run(); ``` -------------------------------- ### Failed Condition Response Source: https://github.com/apigee/api-platform-samples/blob/master/sample-proxies/condition-pattern-matching/README.md Example response when a conditional statement in the proxy fails. It indicates the path suffix that did not match the condition. ```text Condition Failed for proxy.pathsuffix: /animals/cats ``` -------------------------------- ### Successful Condition Response Source: https://github.com/apigee/api-platform-samples/blob/master/sample-proxies/condition-pattern-matching/README.md Example response when a conditional statement in the proxy succeeds. It indicates the path suffix that matched the condition. ```text Condition Succeeded for proxy.pathsuffix: /animals/cats/wild/african/spotted ``` -------------------------------- ### Invoke Sample Proxy Source: https://github.com/apigee/api-platform-samples/blob/master/sample-proxies/access-entity/README.md This script invokes the sample API proxy. Ensure you have replaced the placeholder KEY with a valid API key from your Apigee Edge organization. ```shell KEY="t3AyRHIfbNJwJ6ZbBAxGmNj5YWljAeB" sh invoke.sh ``` -------------------------------- ### Sample Request using curl Source: https://github.com/apigee/api-platform-samples/blob/master/doc-samples/javascript-mashup-cookbook/README.md This is a sample curl command to invoke the API proxy with country and postal code parameters. ```bash curl "http://{org_name}-test.apigee.net/altitude2?country=us&postalcode=08008" ``` -------------------------------- ### Firestore Document Structure Example Source: https://github.com/apigee/api-platform-samples/blob/master/tutorial-demos/firestore-demo/README.md This JSON represents the structure of a document as stored in Firestore, including specific data type wrappers. ```json { "name": "projects/", "fields": { "funny": { "booleanValue": true }, "imagePath": { "stringValue": "https://dakiniland.files.wordpress.com/2011/05/102-0907085235-simpsons-mutant-fish-blinky.jpg" }, "location": { "geoPointValue": { "latitude": 29.987294, "longitude": -39.6875 } }, "punchline": { "stringValue": "A fiiish." }, "text": { "stringValue": "What do you call a fish with 3 eyes?" }, "id": { "stringValue": "8ebb59f9" }, "timestamp": { "timestampValue": "2020-10-08T13:05:29Z" } } } ``` -------------------------------- ### Response Cache Expiry Settings Source: https://github.com/apigee/api-platform-samples/blob/master/learn-edge/response-cache-2/README.md Configures the expiration time for cached responses. This example sets the cache to expire after 3 seconds. ```xml 3 ``` -------------------------------- ### Import API Proxy to Apigee Organization Source: https://github.com/apigee/api-platform-samples/blob/master/perf-proxies/README.md Imports an API proxy archive into your Apigee organization. Replace `${org_name}` with your organization's name. ```bash curl -v 'https://apigee.googleapis.com/v1/organizations/${org_name}/apis?action=import&name=perf' \ -X POST \ -H "Authorization: Bearer $TOKEN" \ -F "file=@perf.zip" \ -H "Content-Type:multipart/form-data" ``` -------------------------------- ### Sample Output: Extract Variables Policy (Query Param) Source: https://github.com/apigee/api-platform-samples/blob/master/samplets/README.md Demonstrates the output when the Extract Variables policy extracts data from a query parameter. ```json { "Feature demonstrated": "Extracted value of {dbncode} parsed from query param: /extract-variables?code=DBN{dbncode}.", "Data extracted": "abc123", "Policy demonstrated": "Extract Variables", "Flow variable written/read": "queryinfo.dbncode" } ``` -------------------------------- ### Execute Cleanup Script Source: https://github.com/apigee/api-platform-samples/blob/master/sample-proxies/oauth-advanced/README.md Use this script to remove entities created by the sample. Provide your organization name, environment, username, password, and management server URL. ```bash ./cleanup.sh ``` ```bash ./cleanup.sh myorg prod test@example.com apigee123 https://api.enterprise.apigee.com ``` -------------------------------- ### Sample Output: Extract Variables Policy (Path Suffix) Source: https://github.com/apigee/api-platform-samples/blob/master/samplets/README.md Demonstrates the output when the Extract Variables policy extracts data from the proxy path suffix. ```json { "Feature demonstrated": "Extract value of {id} parsed from the proxypath.suffix: /extract-variables/resource1/{id}.", "Data extracted": "DBNabc123", "Policy demonstrated": "Extract Variables", "Flow variable written/read": "urirequest.id" } ``` -------------------------------- ### Get Access Token for Apigee APIs Source: https://github.com/apigee/api-platform-samples/blob/master/perf-proxies/README.md Obtains an access token using Google Cloud credentials, required for interacting with Apigee APIs. ```bash gcloud auth login export TOKEN=$(gcloud auth print-access-token) ``` -------------------------------- ### Configure Login App Environment Source: https://github.com/apigee/api-platform-samples/blob/master/sample-proxies/oauth-advanced/README.md Set your Apigee Edge organization, environment, and domain in the login-app's configuration file. ```javascript exports.envInfo = { org: 'Your org name on Edge', env: 'Your environment on Edge (test or prod)', domain: 'apigee.net' }; ``` -------------------------------- ### Modify Condition to Use Java Regex Source: https://github.com/apigee/api-platform-samples/blob/master/sample-proxies/condition-pattern-matching/README.md An example of modifying the condition to use Java Regex for pattern matching. This change affects how the condition is evaluated. ```xml (proxy.pathsuffix JavaRegex "/c*t") ``` -------------------------------- ### Deploy GraphQL Proxy Module Independently with Maven Source: https://github.com/apigee/api-platform-samples/blob/master/sample-proxies/graphql-sample/README.md Deploys only the graphql-proxy module. Navigate to the 'graphql-smp/graphql-proxy' directory. Replace placeholders with your Apigee organization details. ```bash cd graphql-smp/graphql-proxy mvn install -Ptest -Dorg= -Denv= -Dusername= -Dpassword= ``` -------------------------------- ### Basic API Proxy File Structure Source: https://github.com/apigee/api-platform-samples/blob/master/learn-edge/simplest-proxy/README.md This illustrates the fundamental directory structure for an Apigee Edge API proxy. In the simplest proxy, directories like targets, policies, and resources are intentionally left empty. ```text /apiproxy /proxies /targets /policies /resources proxyname.xml ``` -------------------------------- ### Scopes-to-Entitlements Map (KVM) Source: https://github.com/apigee/api-platform-samples/blob/master/sample-proxies/graphql-sample/README.md An example of a JSON object stored in an Apigee KVM that maps scopes to GraphQL entitlements. This is used to authorize queries based on client entitlements. ```json { "instrospect": [ "query.__schema.**" ], "reader": [ "query.__schema.**", "query.resorts.**" ], "site:admin": [ "query.__schema.**", "query.resorts.**", "mutation.resorts.create.**", "mutation.resorts.delete.**", "mutation.resorts.update.**" ], "resort:admin": [ "query.__schema.**", "query.resorts.**", "mutation.resorts.update.**", "mutation.resorts.update.lifts.create.**", "mutation.resorts.update.lifts.update.**", "mutation.resorts.update.lifts.delete.**", "mutation.resorts.update.trails.create.**", "mutation.resorts.update.trails.update.**", "mutation.resorts.update.trails.delete.**" ], "resort:manager": [ "query.__schema.**", "query.resorts.**", "mutation.resorts.update.resort.**", "mutation.resorts.update.lifts.update.**", "mutation.resorts.update.trails.update.**" ] } ``` -------------------------------- ### getFaults Source: https://github.com/apigee/api-platform-samples/wiki/javadocs-javacallout/com/apigee/flow/execution/ExecutionContext.html Fetches all the faults that have occurred during the current execution. ```APIDOC ## getFaults ### Description Fetches all the faults in current execution. ### Method Signature `java.util.Collection getFaults()` ### Returns All the exceptions that occurred during the flow since multiple errors are possible during a flow. ``` -------------------------------- ### Create API Services Cache Source: https://github.com/apigee/api-platform-samples/blob/master/sample-proxies/outbound-oauth/README.md This command creates an API Services Cache in your Apigee environment. Replace $ORG and $ENV with your organization and environment names. Ensure you have the correct XML content in oauth-token-cache.xml. ```bash curl -v -X POST -H "Content-Type: application/xml" -d @oauth-token-cache.xml https://api.enterprise.apigee.com/v1/organizations/$ORG/environments/$ENV/caches -u myname:mypass ``` -------------------------------- ### Benchmark API Performance with Caching Source: https://github.com/apigee/api-platform-samples/blob/master/learn-edge/response-cache-1/README.md Use Apache ab to benchmark API performance with and without response caching enabled. This helps demonstrate the performance improvement. ```bash ab -n 100 -c 10 http://your-org-test.apigee.net/learn-edge/json ``` -------------------------------- ### Get oEmbed Object from Twitter Timeline Source: https://github.com/apigee/api-platform-samples/blob/master/sample-proxies/twitter-oembed/README.md Use this cURL command to request the oEmbed object from the Twitter Timeline API. Ensure the 'Accept: application/json' header is included. ```bash curl -v -H "Accept: application/json" "http://demo-prod.apigee.net/twitter-oembed/search.json?q=from%3Aapigee&result_type=mixed" ``` -------------------------------- ### REST API Response Structure Example Source: https://github.com/apigee/api-platform-samples/blob/master/tutorial-demos/firestore-demo/README.md This JSON shows the simplified REST API response structure offered by the Apigee proxy, mapping Firestore data into a more client-friendly format. ```json { "id": "8ebb59f9", "funny": true, "text": "What do you call a fish with 3 eyes?", "imagePath": "https://dakiniland.files.wordpress.com/2011/05/102-0907085235-simpsons-mutant-fish-blinky.jpg", "timestamp": "2020-10-08T13:05:29Z", "punchline": "A fiiish.", "location": "29.987294, -39.6875" } ``` -------------------------------- ### Make HTTP Request with Javascript Source: https://github.com/apigee/api-platform-samples/blob/master/sample-proxies/async-callout/README.md This Javascript code makes an HTTP GET request to a weather API and stores the response in the session. It's used for initiating an asynchronous callout. ```javascript var paloAlto = httpClient.get('http://weather.yahooapis.com/forecastrss?w=2467861'); context.session['paloAlto'] = paloAlto; ``` -------------------------------- ### Configure Webserver App Variables Source: https://github.com/apigee/api-platform-samples/blob/master/sample-proxies/oauth-advanced/README.md Assign configuration variables within the webserver-app's SetConfigurationVariables policy, including app keys, environment, and organization details. ```xml SetConfigurationVariables appKey Substitute the Consumer key appSecret Substitute the Consumer secret config.environment Substitute your Edge environment (prod or test) config.organization Substitute your organization name on Edge config.domain apigee.net config.protocol https false ``` -------------------------------- ### Deploy API Proxy Revision to Apigee Environment Source: https://github.com/apigee/api-platform-samples/blob/master/perf-proxies/README.md Deploys a specific revision of an API proxy to an Apigee environment. This command is used after the API proxy has been imported. ```bash curl -v 'https://apigee.googleapis.com/v1/organizations/${org_name}/environments/${env_name}/apis/perf/revisions/1/deployments' \ -X POST \ -H "Authorization: Bearer $TOKEN" ``` -------------------------------- ### Deploy Node.js Express API Proxy Source: https://github.com/apigee/api-platform-samples/blob/master/doc-samples/hosted-targets/node-hosted-express/deploy.txt Use this command to deploy a Node.js Express API proxy to a specific Apigee environment. Ensure you have a valid token and the API proxy directory. ```bash get_token && apigeetool deployproxy \ -o apigee-hf-testing \ -e test \ --json \ --token "$(< ~/.sso-cli/valid_token.dat)" \ --api node-hosted-express \ --directory . ``` -------------------------------- ### Get HTML Content from Twitter Timeline Source: https://github.com/apigee/api-platform-samples/blob/master/sample-proxies/twitter-oembed/README.md Use this cURL command to directly retrieve HTML content from the Twitter Timeline API. No specific 'Accept' header is required for HTML output. ```bash curl -v "http://demo-prod.apigee.net/twitter-oembed/search.json?q=from%3Aapigee&result_type=mixed" ``` -------------------------------- ### Invocation Script Source: https://github.com/apigee/api-platform-samples/blob/master/sample-proxies/conditional-policy/README.md Execute this script to test the deployed API proxy. This script likely contains commands to invoke the proxy with different headers. ```bash $ sh invoke.sh ``` -------------------------------- ### Create API Proxy Zip Archive Source: https://github.com/apigee/api-platform-samples/blob/master/perf-proxies/README.md Creates a zip archive of the API proxy files, necessary for importing into Apigee. Navigate to the proxy directory before running this command. ```bash cd api-platform-samples/perf-proxies/perfproxy zip -r perf.zip apiproxy ``` -------------------------------- ### Process Asynchronous HTTP Response Source: https://github.com/apigee/api-platform-samples/blob/master/sample-proxies/async-callout/README.md This Javascript code retrieves a previously stored asynchronous HTTP response from the session, waits for its completion (with a timeout), and then gets the response object. Ensure the delay between initiating the callout and processing the response is sufficient. ```javascript var exchange = context.session['paloAlto']; exchange.waitForComplete(1000); var resp = exchange.getResponse(); ```