[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-09-05。"],[[["\u003cp\u003eThis content is relevant to both Apigee and Apigee hybrid platforms, covering how API proxy requests and responses are handled.\u003c/p\u003e\n"],["\u003cp\u003eBy default, all data from a client's request to an API proxy, including headers, query parameters, form data, and payloads, is passed unchanged to the backend server.\u003c/p\u003e\n"],["\u003cp\u003eThe data within requests and responses are parsed into flow variables that are used during request processing, allowing API proxies to access the information within requests.\u003c/p\u003e\n"],["\u003cp\u003ePolicies can be utilized to modify request or response data, such as adding, removing, or transforming data before it reaches the backend or the client, and multiple different policies can be used to do this.\u003c/p\u003e\n"],["\u003cp\u003eCommon policies like AssignMessage, ExtractVariables, JSONtoXML, and scripting policies like JavaScript can manipulate flow variables, enabling dynamic request and response handling.\u003c/p\u003e\n"]]],[],null,["# Request and response variables\n\n*This page\napplies to **Apigee** and **Apigee hybrid**.*\n\n\n*View [Apigee Edge](https://docs.apigee.com/api-platform/get-started/what-apigee-edge) documentation.*\n\nWhen you make a request to an API proxy, you can pass any or all of the following information,\ndepending on the way the API proxy is configured:\n\n- Request headers\n- Query params\n- Form data\n- XML or JSON payloads\n- Resource URIs\n\nBy default, all data in a request is passed unchanged from the ProxyEndpoint to the\nTargetEndpoint. Therefore, when the TargetEndpoint makes the request to the backend server, all\ninformation in the original request is passed to the backend service.\n\nThe same is true for the response received by Apigee from the backend service. By\ndefault, all data received in the response is passed unchanged to the app that originated the\nrequest.\n\nHow is request data passed to the backend\nserver?\n-------------------------------------------------\n\nThe following image shows an API proxy definition:\n\nFor this API proxy:\n\n- **API proxy virtual host:** `default`\n- **Domain defined by the host names on the environment group:** `http://www.example.com`\n- **Proxy base path:** `/v1/weather`\n- **TargetEndpoint specified by route rule:** `default`\n- **Target URL:** `http://weather.yahooapis.com`\n\nA client app makes a `GET` request to the API proxy by using the following\n`curl` command: \n\n```\ncurl -X GET http://www.example.com/v1/weather/forecastrss?w=12797282\n```\n\nNotice that this request contains the resource `forecastrss` and one query param,\n`w`. Apigee parses the request as\nshown below and assigns parts of the request to flow variables: \n\n```text\n{request.verb} {proxy.basepath}/{proxy.pathsuffix}?{request.querystring}\n```\n\nThe flow variables are set with the following values:\n\n- `request.verb`: `GET`\n- `proxy.basepath`: `/v1/weather`\n- `proxy.pathsuffix`: `forecastrss`\n- `request.querystring`: `w=12797282`\n\n| **Note** : There are many different flow variables created during the processing of a request and response. See [Flow variables reference](/apigee/docs/api-platform/reference/variables-reference) for more.\n\nThe TargetEndpoint then makes a request to the backend service using information from the\nrequest: \n\n```text\n{request.verb} {target.basepath}/{proxy.pathsuffix}?{request.querystring}\n```\n\nNotice how the resource and query params specified in the request are automatically included\nin the request to the backend server. From the definition of the TargetEndpoint, the request then\nhas the form: \n\n```\ncurl -X GET http://weather.yahooapis.com/forecastrss?w=12797282\n```\n\nLike query params, any headers or form params that you include in the request to the API\nproxy are passed on to the backend server. For example, you make the request below that includes\na header: \n\n```\ncurl -X GET -H 'Content-type:application/xml' http://www.example.com/v1/weather/forecastrss?w=12797282\n```\n\nOr a request in the form below to include a header and form data: \n\n```\ncurl -X POST -H \"Content-type:application/json\" -d \\\n '{\"email\" : \"janetutorialxml@example.com\",\n \"firstName\" : \"Jane\",\n \"lastName\" : \"Tutorial\",\n \"userName\" : \"jtutorialxml\"\n }' \\\n http://www.example.com/v1/register/user\n```\n\nIn both examples, the headers and form data are passed unchanged to the backend service. The\nheaders are represented by flow variables such as `request.headers.count` and\n`request.headers.names`. The form data is represented by flow variables such as\n`request.formparam.count` and `request.formparam.names`.\n\nHow is response data returned?\n------------------------------\n\nBy default, all data received by Apigee from the backend service in the response is passed\nunchanged to the app that originated the request. As described above for the request, the data\nreturned in the response is accessible through flow variables on Apigee. For more information,\nsee [Flow variables reference](/apigee/docs/api-platform/reference/variables-reference).\n\nAccess request and response data in\nan API proxy\n------------------------------------------------\n\nThere are many times where you want to modify request data before sending it to the backend\nserver. For example:\n\n- To remove security information used by Apigee to validate requests. That information is not required by the backend service.\n- To add data sent to the backend service, for example to track users or to gather analytics.\n- To conditionally process the request based on request data. For example, an API proxy can have multiple TargetEndpoints. The TargetEndpoint used by the request is determined by request data. You then strip that data from the request before sending it to the backend service.\n\nThe same is true for data in the response. As part of processing the response, the API proxy\nmight want to modify the data before returning it to the requesting app.\n\n### Access request messages\n\nYou can use policies to access and change parts of a request message. These parts include:\n\n- Headers\n- Query parameters\n- Form parameters\n- Source IP address\n- HTTP message body\n\nIn a normal flow, once the request has been processed, the proxy then sends the transformed\nrequest to the target.\n\nPolicies can examine request variables, then transform or reject the request based on the\ncontent of those variables. Policies transform the request by setting the appropriate variables,\nfor example variables corresponding to the request headers.\n| **Tip:** You can use variables to reconstruct the incoming request URL. For example, the following code in a [JavaScript policy](/apigee/docs/api-platform/reference/policies/javascript-policy) assembles the request URL from its parts: \n|\n| ```gdscript\n| var req_verb = context.getVariable('request.verb');\n| var req_scheme = context.getVariable('client.scheme');\n| var req_host = context.getVariable('request.header.host');\n| var req_request_uri = context.getVariable('request.uri');\n| var req_url = req_scheme + \"://\" + req_host + req_request_uri;\n| ```\n|\n| The result of the concatenation might look like the following: \n|\n| ```text\n| https://www.example.com/sample\n| ```\n\n### Access response messages\n\nUsing the variables that apply to the response message, policies may access message components\nincluding the header, the query parameters, and form parameters, the source IP address, the HTTP\nmessage body, and so on.\n\nThe proxy receives a response message, then applies to it a series of policies, based on\nconditions evaluated on the response, which can modify or transform the response.\n\nPolicies can examine response variables, then transform or reject the request based on the\ncontent of those variables. Policies transform the response by setting the appropriate variables,\nfor example variables corresponding to the response headers.\n\n### Common policies to access flow variables\n\nApigee defines several policies that you can use to process the request and response data. These\npolicies include:\n\n- [AssignMessage policy](/apigee/docs/api-platform/reference/policies/assign-message-policy): Creates or modifies HTTP request or response messages during an API proxy flow. Also creates and populates new flow variables.\n- [ExtractVariables policy](/apigee/docs/api-platform/reference/policies/extract-variables-policy): Extract content from messages, including headers, URI paths, payloads, and query parameters, for use in a condition statement. The policy then applies a text pattern to message content and upon finding a match sets a designated variable.\n- [JSONtoXML policy](/apigee/docs/api-platform/reference/policies/json-xml-policy) and [XMLtoJSON policy](/apigee/docs/api-platform/reference/policies/xml-json-policy): Convert messages from JavaScript Object Notation (JSON) to the extensible markup language (XML) format, or vice versa.\n- [JavaCallout policy](/apigee/docs/api-platform/reference/policies/java-callout-policy), [JavaScript policy](/apigee/docs/api-platform/reference/policies/javascript-policy), [PythonScript policy](/apigee/docs/api-platform/reference/policies/python-script-policy), [RegularExpressionProtection policy](/apigee/docs/api-platform/reference/policies/regular-expression-protection): These policies let you write a script to access flow variables containing request and response data."]]