Getting rid of request parameters from the request

In most service chaining and API invocations we might come across situations where we will require to remove the initial request URI from the request. If we take for an example the following scenario. 1. We need to obtain some parameters from the users of our API. Therefore we define a resource as below which takes the name and age

What we really need to do is get the name of the student and return the exam grades information. For that we need to invoke a URL in the following format.

http://www.mocky.io/v2/59a3e86f130000b013ce056d/getGrades/{query.param.name}

But with the request URI already been defined in step (1) the request which will be sent is the one below

http://www.mocky.io/v2/59a3e86f130000b013ce056d/getGrades/{query.param.name}?name=Jessie&age=20

Since the backend does not identity a request with such trailing parameters it will fail. How can we get rid of the trailing query parameters from the request (1)?? It’s pretty simple. We have a property in the WSO2 synapse which handles these kind of use cases. When we add the property into our in sequence we can get rid of the trailing request URI. By using this property we then remove the intial request URI

<property name=”REST_URL_POSTFIX” scope=”axis2" action=”remove”/>

After this property is added the requst will be sent out in the following format which is what we finally need.

http://www.mocky.io/v2/59a3e86f130000b013ce056d/getGrades/{query.param.name}

You can add this to your API using custom sequences.

References