API / APIGEE Gateway Interview Questions
What is the AssignMessage policy and what can it do?
The AssignMessage policy is one of the most-used policies in Apigee. It lets you create, modify, or remove HTTP message components (headers, query parameters, form parameters, body, verb, path) on either the request or the response. It is used for protocol bridging, header injection, body transformation, and creating custom responses.
<!-- Set headers on the outgoing request to backend --> <AssignMessage name="AM.SetBackendHeaders"> <AssignTo createNew="false" type="request"/> <Set> <Headers> <Header name="x-internal-caller">apigee-proxy</Header> <Header name="x-correlation-id">{request.header.x-correlation-id}</Header> </Headers> </Set> <Remove> <Headers> <Header name="x-api-key"/> <!-- strip the key before forwarding --> </Headers> </Remove> </AssignMessage> <!-- Create a custom error response --> <AssignMessage name="AM.CustomError"> <AssignTo createNew="true" type="response"/> <Set> <StatusCode>403</StatusCode> <ReasonPhrase>Forbidden</ReasonPhrase> <Headers> <Header name="Content-Type">application/json</Header> </Headers> <Payload contentType="application/json">{ "error": "access_denied", "message": "You do not have permission to call this API." }</Payload> </Set> </AssignMessage> <!-- Change the request verb and path --> <AssignMessage name="AM.RewritePath"> <AssignTo createNew="false" type="request"/> <Set> <Verb>POST</Verb> <Path>/v2/orders</Path> </Set> </AssignMessage>
More Related questions...