Bug 36 - query/retrieve Rest API: /retrieve route shall accept application/json content type
Summary: query/retrieve Rest API: /retrieve route shall accept application/json conten...
Status: RESOLVED FIXED
Alias: None
Product: Orthanc
Classification: Unclassified
Component: Orthanc Core (show other bugs)
Version: unspecified
Hardware: All All
: --- enhancement
Assignee: Sébastien Jodogne
URL:
Depends on:
Blocks:
 
Reported: 2020-06-29 15:12 CEST by Sébastien Jodogne
Modified: 2020-06-29 15:20 CEST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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 !