Skip to Content
0

How to make XSJS service to return .

Feb 20, 2017 at 12:33 PM

95

avatar image

Hello Experts,

I have a requirement to create an XSJS service which should have both

<Content-Type: application/json> and <Accept: application/json>.

I have a sample code below, am bit confused:

var ReqBody = $.request.body.asString();
ReqBody = JSON.parse(ReqBody);
$.response.status = $.net.http.OK;
$.response.setBody(JSON.stringify(
		{
			"name" : ReqBody.id
			
		}
));
$.response.contentType = "application/json";	
$.response.headers.set("Access-Control-Allow-Origin", "*");

I am getting the response in json format, but am not sure if the Accept is in Json or not.

Request you to please guide me.

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

ritu s jain Feb 21, 2017 at 01:57 PM
0

Hi,

You may like the sender (the caller of your XSJS) to pass a parameter which specifies whether the output needed is in the JSON or in text. Based on the input you can set the content type while returning the object to response.

Share
10 |10000 characters needed characters left characters exceeded