Question
· Mar 5, 2021

Creating a RESTFul Service, why custom method does not return the expected JSON?

FIrst of all thank you for your time in reading this question and writing a response,

We would need some help,

-> Our objective is to control which method is being used in the service: GET POST PUT

We have tried to understand the example REST Service: Demo.REST.DirectoryService

 

After that we have tried to create our own custom rest service,

please take a few minutes to examine the following code:

 
Code

We are able to use "retrievePerson" succesfully

We send:

http://localhost:19622/aplicaciones/scs/test/miscs/employee/name/Q*/salary

We observe:

With headers:

 

Here comes the challenge:

When we issue:

http://localhost:19622/aplicaciones/scs/test/miscs/consultarImagen

With the following body:

{
    "idApp": "miHistoria",
    "usuario": "11473564",
    "numExpediente": "11473564"
}

It replies nothing:

With the headers:

Besides if we check the trace we see:

 

 

Why we do not see the reply in POSTMAN?

Why headers are "text/html" and not "application/json"?

Could you help us?

 

We have read:

https://docs.intersystems.com/latest/csp/documatic/%25CSP.Documatic.cls?...

https://docs.intersystems.com/latest/csp/docbook/Doc.View.cls?KEY=GREST_...

 

Could you point us to some code, examples or documentation?

 

Thank you for your replies

Discussion (12)2
Log in or sign up to continue

Thanks Marc Mundt for your reply

Yes you are right, we should use POST

We have changed it:

<Route Url="/consultarImagen" Method="POST" Call="consultarImagen"/>

However we do not see the response in POSTMAN:

And the headers are:

Content-Type: text/html

Content-Length: 0

CACHE-CONTROL: no-cache

PRAGAM: no-cache

We send the POST to the following URL:

http://localhost:19622/aplicaciones/scs/test/miscs/consultarImagen
 

Besides we observe the response message being converted from Ensemble object to JSON in the service:

We do see the Response Message from the Operation to the Service

Why we do not see the JSON being replied from the Service in POSTMAN?

How could we debug this behaviour?

Thanks for your replies

Thanks Marc Mundt for your attention, and your helpful reply

 
Our current code is:

When we dig deeper using Whireshark:

First, we find that the method in the example that uses GET, the retrievePerson, does answers with a JSON to POSTMAN, so it works:

GET request:

GET response:

In POSTMAN:

However,

Our custom method: consultarImagen which is a POST

Shows nothing in POSTMAN

Why?

POST request:

POST response:

In POSTMAN:

Could you help us?

Thanks for your replies

Why would be better or recommended to use %CSP.REST directly, instead of EnsLib.REST.Service?

To start with using %CSP.REST is the recommended way to use REST with productions.

Are there any improvements if we use %CSP.REST?

It's easier to develop, there are more examples available, you can have a combined production/non-production REST services easily.

Hi Eduard,

I am looking for some examples of REST API served through production. Would you be able to point me to some, please? 

I am trying to implement a business service,  process and operation that serves bundle of apis related to a domain and resource e.g Patient , Patient alerts, patient status . These will be 3 api urls served by single business service,  process and operation.  

I am also looking for best practice to handle various http responses in BP and BO.

Would greatly appreciate if you can direct me to relevant examples. 

Thank you,

Utsavi