Skip to content

Register a corpus POSTing JSON #365

@ingoboerner

Description

@ingoboerner

Creating a corpus via POST /corpora with Content-Type: application/json always fails with HTTP 500. The JSON handler function api:corpora-post-json references the variable $auth, but — unlike its XML counterpart — never declares it (neither as a %rest:header-param nor as a function parameter). The function therefore fails XQuery static analysis and can never execute.

The XML variant (Content-Type: application/xml) is unaffected and works correctly.

curl -u 'admin:' -X POST \
  -H 'Content-Type: application/json' \
  -d '{"name":"probe","title":"Probe"}' \
  http://localhost:8088/api/v1/corpora

Add the Authorization header-param annotation and the $auth parameter to api:corpora-post-json, mirroring api:corpora-post-tei:

declare
  %rest:POST("{$data}")
  %rest:path("/v1/corpora")
  %rest:header-param("Authorization", "{$auth}")
  %rest:consumes("application/json")
  %rest:produces("application/json")
  %output:media-type("application/json")
  %output:method("json")
function api:corpora-post-json($data, $auth) {
  if (not($auth)) then ...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions