# Testing Restful webservices

**URL:** <https://forum.servoy.com/t/testing-restful-webservices/16848>\
**Category:** Classic Servoy\
**Created:** [December 14, 2012, 10:05pm UTC](https://forum.servoy.com/t/testing-restful-webservices/16848 "2012-12-14T22:05:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Adelo\_Herrero](https://avatars.discourse-cdn.com/v4/letter/a/96bed5/32.png) [@Adelo\_Herrero](https://forum.servoy.com/u/Adelo_Herrero)\
**Post date:** [December 14, 2012, 10:05pm UTC](https://forum.servoy.com/t/testing-restful-webservices/16848/1 "2012-12-14T22:05:54Z")

</div>

Hi all:

I continue testing the Restful webservices following the Servoy Wiki examples:  
[http://wiki.servoy.com/display/public/DOCS/RESTful+Web+Services](http://wiki.servoy.com/display/public/DOCS/RESTful+Web+Services)

In my ws\_read() I type the code:

```auto
for (var i = 0; i < arguments.length; i++) {
     if (typeof arguments[i] == 'string') { //The URL path additions are passed in as Strings
         application.output('URL Path addition: ' + arguments[i])
     } else {
         for each (var key in arguments[i]) {
              application.output('Query Parameter "' + key + '", values: "' + arguments[i][key].join(', ') + '"')
         }
     }
}

```

In theory, If I type [http://localhost:8080/servoy-service/re … at&pet=Dog](http://localhost:8080/servoy-service/rest_ws/testWs/myForm/foo/bar?name=John&age=30&pet=Cat&pet=Dog) in the web browser, the application should be displayed in the console:

URL Path addition: foo  
URL Path addition: bar  
Query Parameter “name”, values: “John”  
…

Unfortunately it only show:  
URL Path addition: foo  
URL Path addition: bar

In debug mode, I get the following results:

=\>arguments[0]  
“foo”  
=\>arguments[1]  
“bar”  
=\>arguments[2]  
Object {age:array[1],name:array[1],pet:array[2]}  
=\>key  
[“Cat”,“Dog”]

I understand that, the key value should be “name” and not the key values.

I can get the key name if I typing in debug mode:  
=\>arguments[2].name[0]  
“John”  
But I need know before the object structure.

Summarizing the post; I need get the key name for check if it is valid in my application, and evidently your value.

Any idea?  
Thanks in advance.  
Best regards.

---

<div class="post-metadata">

**Author:** ![ptalbot](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/ptalbot/32/4952_2.png) [@ptalbot](https://forum.servoy.com/u/ptalbot)\
**Post date:** [December 14, 2012, 10:21pm UTC](https://forum.servoy.com/t/testing-restful-webservices/16848/2 "2012-12-14T22:21:22Z")

</div>

At the risk of being taxed as trying to lead you to a big learning curve (which is far from the truth), I would recommend using Velocity, which will ease your pain when receiving parameters and parsing them

With [http://localhost:8080/servoy-service/ve … at&pet=Dog](http://localhost:8080/servoy-service/velocity/testWs/myForm/foo/bar?name=John&age=30&pet=Cat&pet=Dog).  
You would receive a JavaScript object like this:

```auto
request : {
    method: "get",
    extraPaths: ["foo", "bar"],
    parameters: {name: "John", age: "30", pet: ["Cat", "Dog"]},
    headers: {},
    cookies: [],
    // etc...
}

```

---

<div class="post-metadata">

**Author:** ![Adelo\_Herrero](https://avatars.discourse-cdn.com/v4/letter/a/96bed5/32.png) [@Adelo\_Herrero](https://forum.servoy.com/u/Adelo_Herrero)\
**Post date:** [December 15, 2012, 6:41am UTC](https://forum.servoy.com/t/testing-restful-webservices/16848/3 "2012-12-15T06:41:15Z")

</div>

I answer to my self. If I change the code:

```auto
for each (var key in arguments[i]) 
...

```

by

```auto
for (var key in arguments[i])
...

```

It show the correct result.

Thanks for the replies.

---

<div class="post-metadata">

**Author:** ![antonio](https://avatars.discourse-cdn.com/v4/letter/a/6de8d8/32.png) [@antonio](https://forum.servoy.com/u/antonio)\
**Post date:** [December 18, 2013, 6:15am UTC](https://forum.servoy.com/t/testing-restful-webservices/16848/4 "2013-12-18T06:15:00Z")

</div>

In Servoy 5.2 ended up using a different approach to parse a query (tip of the hat to GoldCougar for the suggestion).  
Instead of directly calling servoy WS, the external service calls a .jsp file placed in application\_server/server/webapps/ROOT  
e.g. “[https://myserver.com/callback.jsp?Reference=1234&Result=OK&ResultCode=F](https://myserver.com/callback.jsp?Reference=1234&Result=OK&ResultCode=F)”

The jsp converts the values of the known query params into path extensions,  
It looks like

```auto
<%
	String redirectURL = "http://localhost:8080/servoy-service/rest_ws/mySolution/myForm";
	
	if (request.getParameter("Reference") == null) 
        redirectURL += "/null";
    else
        redirectURL += "/" + request.getParameter("Reference");
        
	if (request.getParameter("Result") == null) 
        redirectURL += "/null";
    else
        redirectURL += "/" + request.getParameter("Result");

	if (request.getParameter("ResultCode") == null) 
        redirectURL += "/null";
    else
        redirectURL += "/" + request.getParameter("ResultCode");
        
	response.sendRedirect(redirectURL);
%>

```

The last line calls the servoy WS with the new URL, in this example  
“[http://localhost:8080/servoy-service/rest\_ws/mySolution/myForm/1234/OK/F](http://localhost:8080/servoy-service/rest_ws/mySolution/myForm/1234/OK/F)”  
and executes the ws\_read method with the arguments 1234, OK, F.

Maybe there’s a way to do it all in Servoy, but try as I might, I can’t read the query parameters from a GET call to Servoy WS.
