How to add interceptors from Policy Hub¶
Initialize and setup a Microgateway Project.¶
Run below command to initialize a new microgateway project with an openapi definition.
micro-gw init petstore -a https://raw.githubusercontent.com/wso2/product-microgateway/v3.0.4/samples/petstore_basic.yaml
Include the extensions in the OpenAPI definitions using the policy sharing syntax¶
Now we have a project initilized for petstore API. Next step is to add required extensions to engage the interceptors from Policy hub. For this we can use
x-wso2-response-interceptor extensions. To see complete usage details of these extensions, check adding interceptors .
- Open the
x-wso2-basePath: /petstore/v1extension, add
Interceptor reference should be provided in following format.
<ballerina_org>/<ballerina_module>/<ballerina_module_version>:<interceptor_function>. If version is not provided, latest version of the specified module will be engaged.
Build and run Microgateway Project¶
Lets build and run the project to see if new interceptors are working.
Build the petstore project.
micro-gw build petstore
Start the gateway.
Send a request to petstore API. This request should fail since we don't mention the required header X-API-Key which is validated inside the prasadhi/Interceptors:validateRequest interceptor.
curl -k -H "Authorization: Bearer $TOKEN" -X GET https://localhost:9095/petstore/v1/pet/1
Now send the correct request to see if it gives the correct response
curl -k -H "Authorization: Bearer $TOKEN" -H "X-API-Key: apikey-value" -X GET https://localhost:9095/petstore/v1/pet/1
Thats how you could configure Microgateway to use shared interceptors through Policy Hub. To see more detailed information on this feature checkout the feature documentation at the policy hub .Top