Question
Thembelani Mlalazi · Sep 16

REST Service how to accept a Json request

I have a REST Service that I want it to receive a json string request I have set up my URLMap as follows the top URL when populated and requested works fine but I would like my request to be a json string and that is not working I am getting a 500 error am I missing something please advice.

 

XData UrlMap
{
<Routes>
<Route Url="/:emailAddress/:sendUserEmail/:password" Method="POST" Call="ResetPassword"/>        this works fine
<Route Url="/test" Method="POST" Call="test"/>              I would like this to receive a json formatted string for the above
</Routes>
}

Product version: Caché 2018.1
$ZV: Cache for Windows (x86-64) 2018.1.4 (Build 505_1U) Thu May 28 2020 10:01:40 EDT [HealthShare Modules:Core:15.032.9035 + Linkage Engine:15.032.9035]
0
0 118
Discussion (5)1
Log in or sign up to continue

How did you define your test method?

Hi.

You can find it in:

%request.Content

Regards,
Matjaž

Hello, Thembelani,

I have implemented a similar case in this app:

https://github.com/oliverwilms/irisrest/blob/master/src/App/REST.cls#:~:...

Important helper method is this:

/// Helper method
ClassMethod GetJSONFromRequest(Output obj As %DynamicObject) As %Boolean
{
    Set ok = 1
    Try {
        Set obj = ##class(%DynamicObject).%FromJSON(%request.Content)
    } Catch ex {
        Set ok = 0
    }
    Quit ok
}

Best regards,

Oliver

I have set up this service within Ensemble using the the "EnsLib.HTTP.InboundAdapter"; if any one has done this before please advice currently I have done everything as per advices and followed through the ENSDEMO namespace examples still can not pass a JSON request