Setting ContentType in Rest Service
Hello,
I am working on a Rest Service that should accept a particular content type. How and where can I set the value?
I have tried setting the value %response.ContentType by overriding Page method OnPreHttp() but from what I see this method never got executed.
Thanks
Raghu
If you use %CSP.REST, you can set needed ContentType in any called method
and test
Thank you for trying to help me. I am not looking to set the Response ContentType. I am trying to set accepted content type.
Thanks
Raghu
Well, in this case you should set Header Accept, with needed one or more formats, more info in wiki
Where do you suggest me to add that line? In any method or OnPreHttp() method?
In any method, as in example with ContentType
Dmitry,
That did not help. Let me phrase my question different way, by Default ContentType of a Rest business service is text/html, I want that to change to application/x-www-form-urlencoded. When my client posts the data as application/xml or text/xml. I am able to extract the stream from Input object. But when my client sends the contant type as application/x-www-form-urlencoded, in service class I am getting empty stream.
So I am trying to match the content type with the client.
Thanks
Raghu
So, you had to start with such explanation.
Well, does not matter what do you set in Accept header, if you don't use it by yourself. Like, you should check incoming content type and send an error if it is not accepted. This Header change nothing in incoming data, if data was sent in another format.
To read data, you should know that %request has three different ways for getting data. You have already known in %request.Content, which usually contains binary streams. Then %request.MimeData, and %request.Data, it is a Multidimensional properties, and %request has some getters for them, %request.GetMimeData and %request.Get. MimeData, needs when client send data in multipart mime format, such as several files or so on. And %request.Data, in all most cases, and you should look at this property and method %request.Get("somename")
Thank you, Dmitry. Your direction helped me. I found the document that explains the %request object. So, in this case pInput parameter doesn't hold any info?
Thanks
Raghu
As I see you a talking about Ensemble REST service. In this case I am not 100% sure, I think pInput only contains some binary data, or json. But forms data any should be available with %request.
Thanks for your help.
If you are publishing a RESTful service then you don't set the Accepted Content type. This is for the client to inform you as to what they responses they can accept. So your rest service would examine this value to verify that you can supply the type of response the client will accept. You would access this value using this syntax:
%request.CgiEnvs("HTTP_ACCEPT")
Hi Raghu,
Stream objects have an Attributes collection which holds the incoming HTTP headers. I believe you should be able to check the incoming Content Type with pInput.GetAttribute("Content-Type") but I haven't confirmed this.
-Brendan
Thank you, Brendan. I am already doing this to find out what is the content type of incoming request.
Thanks
Raghu
Social networks
InterSystems resources
Log in or sign up
Log in or create a new account to continue
Log in or sign up
Log in or create a new account to continue
Log in or sign up
Log in or create a new account to continue