Mehdi Alisoltani
Mehdi Alisoltani

Reputation: 409

How wso2 api manager add custom header to a request passing to backend

I have created an API in WSO2 API Manager and I want to add a custom header when API gateway receive the request and set the custom header to the API and pass it to back end. for example when API gateway receive the request for every request of this type adds "My-Header : xxxxx" to the request and pass it to back end.

How is it possible ?

Upvotes: 2

Views: 3682

Answers (3)

You can achieve this via various methods as mentioned below.

  1. Publisher portal: If you want to add a custom header along with the request itself, you can add it as follows in the publisher portal. enter image description here

  2. Via custom mediation: If you want to add the custom header in the gateway component, you can use either a custom sequence built using a header mediator. This is appropriate to be used if your requirement is simple and doesn't have any complicated logic to be addressed. If you want to add the custom header to a specific API, then you can add the custom mediation only to that API. In case if you want to add it to all the APIs as a global solution, then you can add it as a global sequence.

  3. Via custom handler: If you have a complicated requirement in adding the custom header and if you want to add the header in the gateway component, you can use a custom handler to achieve this.

Upvotes: 5

Anonymous
Anonymous

Reputation: 56

You can add an in-sequnce as below:

<sequence name="test" xmlns="http://ws.apache.org/ns/synapse"> 
<property name="<NAME>" value="<VALUE>" scope="transport"/>
<property name="<NAME>" value="<VALUE>" scope="transport"/> 
</sequence> 

Upvotes: 2

Sarangan
Sarangan

Reputation: 1017

You can use a custom sequence or header mediator for this purpose.

From a long term perspective, you can write a custom handler for your specific goal.

Upvotes: 3

Related Questions