Skip to Content

How to make XSJS service to return .

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.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • avatar image
    Former Member
    Feb 21, 2017 at 01:57 PM

    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.

    Add comment
    10|10000 characters needed characters exceeded