Bug 36

Summary: query/retrieve Rest API: /retrieve route shall accept application/json content type
Product: Orthanc Reporter: Sébastien Jodogne <s.jodogne>
Component: Orthanc CoreAssignee: Sébastien Jodogne <s.jodogne>
Status: RESOLVED FIXED    
Severity: enhancement    
Priority: ---    
Version: unspecified   
Hardware: All   
OS: All   

Description Sébastien Jodogne 2020-06-29 15:12:06 CEST
[BitBucket user: Alain Mazy]
[BitBucket date: 2017-03-13.21:51:42]

Many of these methods only accept the AET as the body of the POST request but fails if the AET is passed as a single string with the content-type set to application/json.  That would be more RestFull to accept json requests as well.

in the integratin tests, we do have

DoPost(_REMOTE, '/queries/%s/answers/0/retrieve' % a, 'ORTHANC')

while we should also accept something like:

DoPost(_REMOTE, '/queries/%s/answers/0/retrieve' % a, 'ORTHANC', 'application/json')


i.e: 
```
static void RetrieveOneAnswer(RestApiPostCall& call)
  {
    size_t index = boost::lexical_cast<size_t>(call.GetUriComponent("index", ""));

    std::string modality;
    call.BodyToString(modality);
```
instead of that, we should have something like:
```
static void RetrieveOneAnswer(RestApiPostCall& call)
  {
    size_t index = boost::lexical_cast<size_t>(call.GetUriComponent("index", ""));
   if (call.ParseJsonRequest(request))
   {
      modality = request.asString()
   }
   else
   {
      std::string modality;
      call.BodyToString(modality);
   }

```
Comment 1 Sébastien Jodogne 2020-06-29 15:20:17 CEST
[BitBucket user: Alain Mazy]
[BitBucket date: 2017-07-10.19:12:47]

added a test in https://hg.orthanc-server.com/orthanc-tests/changeset/9d09f6f21b60bcc3a2f3623de52ed5d1e7e6ab76

it works already !