Mehdi Alisoltani
Mehdi Alisoltani

Reputation: 409

Changing Header In WSO2 API Manager

Is it possible to change a header of an API in wso2 api manager ? Suppose you have an API with the required header user-key:user-value and you want to change it to backend-key:user-value.

I want to know is this possible ?

Upvotes: 0

Views: 702

Answers (2)

chashikajw
chashikajw

Reputation: 828

This can be done by writing a class mediator also. If there is a request that comes with backend-key header, you can get that and set that as the user-key header. This can be done by writing a class mediator. You can write the logic inside the mediator. Refer to this documentation https://apim.docs.wso2.com/en/latest/learn/api-gateway/message-mediation/adding-a-class-mediator/.

Upvotes: 0

Pubci
Pubci

Reputation: 4001

Using a custom sequence you can do this easily as follows.

<sequence xmlns="http://ws.apache.org/ns/synapse" name="header_sequence">
   <property name="user-value" expression="$trp:user-key"/>
   <header name="backend-key" scope="transport" expression="get-property('user-value')"/>
   <property name="user-key" scope="transport" action="remove"/>
</sequence>
  1. Reads the user key header
  2. Adds the backend-key header with the user key header value
  3. Deletes the user key header. Otherwise, it passes to the backend.

Upvotes: 1

Related Questions