cancel
Showing results for 
Search instead for 
Did you mean: 

How to handle POST request in XSJS Application?

0 Kudos

Hello everyone,

There is a simple method to get parameters from URL with $.request.parameters.get(name) -> so the request method has been set to GET. However, at the same time I cannot find information in the documentation how to handle POST, PUT or DELETE methods. What is more, in the documentation (XSJS - WebRequest) there is an code example which shows that there is one and only supported method => GET (code below)...

if($.request.method === $.net.http.GET) {
   // get query parameter named id
   var qpId = $.request.parameters.get("id");
   
   // handle request for the given id parameter...
   var result = handleRequest(qpId);
   
   // send response
   $.response.contentType = "plain/test";
   $.response.setBody("result: " + result);
   $.response.status = $.net.http.OK;
} else {
   // unsupported method
   $.response.status = $.net.http.INTERNAL_SERVER_ERROR;
}

XSJS - TupelList - only get method exists

Vaibhav_Sapra
Participant
0 Kudos

Hello sushuang,

I am trying to do the same, but my table has more than say 500 records. I am able to implement the logic using a for loop in xsjs. but it works fine till 200 rows and throws an error when data set is more than 200 rows!

Do you have any idea what can be done here?

florian.pfeffer

Posted on

Thanks,

Vaibhav Sapra

Accepted Solutions (1)

Accepted Solutions (1)

pfefferf
Active Contributor

The get method in the TupelList has nothing to do with the HTTP GET method. The get in the TupelList returns the entry of the TupelList with the name you pass as parameter to the get method. If you are executing an HTTP GET request with URL parameters (e.g. ../test.xsjs?testParam=1) then the $.request.parameters.get call returns the parameter value (e.g. $.request.parameters.get('testParam') => 1).

When you do a e.g. a POST or PUT request you pass normally your parameters as payload in the body (e.g. as JSON string). This can be accessed by $.request.body. This is a $.web.Body. With method asString you can get the body as string. If it is a JSON string, you can easily convert it to a JSON object with JSON.parse for further usage.

0 Kudos

Ok, now I see! Thank you for your response. However, it's a pitty that there is no easy way to get parameters from POST or PUT and we have to parse request to JSON and then look for a parameter in loop. For me it's some kind of workaround than how it should works. What is more, it's really confusing that in documentation I've found that there is only one supported method => GET (code in my question).

Thanks again, Damian

Answers (0)