Skip to main content

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.

[1] https://docs.wso2.com/display/ESB470/HTTP+Transport+Properties#HTTPTransportProperties-Property:REST_URL_POSTFIXREST_URL_POSTFIX
[2] https://docs.wso2.com/display/AM210/Adding+Mediation+Extensions


Comments

Popular posts from this blog

WSO2 Cloud

Introduction WSO2 Cloud consists of three commercial cloud offerings namely the API cloud, Integration Cloud and the Identity Cloud. WSO2 Integration Cloud WSO2 Integration Cloud is a public hosted version of the powerful, 100% open-source WSO2 Enterprise Integrator. It allows you to host your cloud-to-cloud, cloud-to-on-premise integrations and API backends on a scalable cloud platform WSO2 API Cloud WSO2 API Cloud is an enterprise-ready, self-service platform that enables you to expose business capabilities as managed APIs and leverage off-the-shelf potential for advertising and selling business APIs. The API Cloud supports all aspects of an API’s lifecycle, from its creation to publication and retirement. The API Cloud is based on WSO2 API Manager , WSO2’s complete solution for designing and publishing APIs and managing a developer community. [2] WSO2 Identity Cloud WSO2 Identity Cloud leverages the functionality of WSO2 Identity Server’s identity and ac...

Exposing a SOAP service as a REST API

In this post i will be explaining how we can transform a SOAP based backend to receive requests in a restful manner through the WSO2 API Cloud. Steps. First log into the WSO2 Cloud and navigate to the API Cloud. In the API cloud select the option to add a new API. We will be creating an API to demonstrate an invocation to the backend soap service ws.cdyne.com/phoneverify/phoneverify.asmx?wsdl Give a name, context and version to the API and add a resource name with a GET Method. The resource name can be anything which you like since we will invoke the actual service usiing a custom sequence. Mention the URI template as indicated in the below screenshot. Next go to the implement tab. And select the endpoint type as HTTP/SOAP Endpoint and specify the endpoint as http://ws.cdyne.com/phoneverify/phoneverify.asmx. There is an important step we need to do here. We need to set the SOAP version for this request. In order to do that we need to select the advanced option ...

Adding error sequence to a custom sequence

In my previous posi i explained how to call an endpoint using the call mediator. Usually when errors are thrown from the call mediator we can handle them using a custom sequence. When call mediators fails the execution stops hence handling errors is very essential. For this post I will be modifying the same sequence which i created in the blog post [1] The change which we need to do is we need to modify the sequence definition to map with the error sequence as shown below. You can find the modified sequence here . <sequence xmlns="http://ws.apache.org/ns/synapse" name="countrySequenceWithError" onError="countryErrorSequence"> <property name="uri.var.countryCode" expression="$url:countryCode"/> <property name="REST_URL_POSTFIX" scope="axis2" action="remove"/>     <call blocking="true">         <endpoint>             <http method="get" uri-temp...