Microsoft Certified: Azure Developer Associate (AZ-204)Connect to and consume Azure services and third-party servicesHard
A development team is building a new application that uses Azure API Management (APIM) to expose its backend APIs. They need to implement a policy that transforms the request body by adding a new property to the JSON payload before forwarding the request to the backend service. This new property contains an internal identifier that should not be exposed to external consumers. Which APIM policy should be used?
- A<code><rewrite-uri></code>
- B<code><cache-lookup></code>
- C<code><set-body></code>
- D<code><set-header></code>
Show answer & explanationAnswer & explanation
Correct answer: C. <code><set-body></code>
The <code><set-body></code> policy in Azure API Management allows you to modify the request or response body. By using an expression, you can parse the existing JSON payload, add a new property, and then re-serialize it, effectively transforming the request body before it reaches the backend service.
Why the other options are wrong
- A. <code><rewrite-uri></code> modifies the URL of the request, not its body.
- B. <code><cache-lookup></code> is used for retrieving responses from the cache, not for transforming request bodies.
- D. <code><set-header></code> is used to add or modify HTTP headers, not the request body.
APIM <set-body> Policy
An Azure API Management policy used to set the content of the request or response body.
- Allows modification of JSON, XML, or other body content.
- Can use expressions to dynamically transform data.
- Applied in either inbound or outbound processing sections.
Memory trick: APIM policies are the rules that shape your API's behavior.