About this task
You want to enhance the security of your e-commerce API by implementing a custom security
header, X-Api-Consumer-Secret
, in the incoming requests. This header must
carry an API secret key and be present in all requests. You can use this header to authorize
API requests.
Before you begin
Ensure that you have:
- Manage APIs or Activate/Deactivate APIs functional privilege. If you are an
Administrator, you would have this privilege by default.
- A sample REST API file to create an API using the importer. For example, you can
download the sample ConsumerAPI from the Github repository.
To transform the API request header
Procedure
-
Click APIs in the title navigation bar.
-
Click Create API to create an e-commerce REST API. For example,
you can use the sample ConsumerAPI from the Github repository.
-
Select Import API from file. Click Browse
and select the ConsumerAPI file.
-
Provide the following details:
- Name: ConsumerAPI
- Description: E-commerce API
- Version: 1.0
-
Click Create.
-
Click Edit to add the Request Transformation policy.
-
Select Policies > Request Processing > Request
Transformation.
The Request Transformation policy properties section appears.
-
In the Condition section, select OR.
The configured transformation is applied when at least one of the conditions is
satisfied.
Note: The condition can also be set to AND operator. The configured transformation is
applied only when all the set conditions are satisfied.
-
Click Add Condition to configure the conditions to evaluate the
contents on the request.
-
Provide the following information:
- Variable:
${request.headers.X-Api-Consumer-Secret}
- Operator: Equals
- Value: xyz
This condition checks for the presence of the X-Api-Consumer-Secret
header with a specific value. In this case, xyz
.
-
Click Add.
The condition to authorize the API request is created.
-
Select Transformation Configuration > Header/Query/Path
transformation.
The Header/Query/Path transformation section appears.
-
In Add/Modify section, provide the following information:
- Variable:
X-Api-Provider-Secret
- Value: 123
-
Click Add.
-
Click Save.
If the condition to authorize the API request is met, webMethods API Gateway transforms the request
by adding a new header, X-Api-Provider-Secret
with the API secret key
value 123
and authorizes the API request.