kuzzleio / kuzzle

Open-source Back-end, self-hostable & ready to use - Real-time, storage, advanced search - Web, Apps, Mobile, IoT -
https://kuzzle.io
Apache License 2.0
1.43k stars 123 forks source link

inconsistency between WS and AJAX data #1098

Closed Tyki closed 6 years ago

Tyki commented 6 years ago

The data given for a plugin controller are not in the same place, based on WS or AJAX.

I declared a POST endpoint in my custom plugin.

On WS, using Kuzzle SDK JS : Kuzzle.query({controller: 'plugin/Controller', action: 'myAction'}, {payload: {}}. => The payload object is inside request.input.args

Using Ajax, with the same controller/action and the same payload, the data will be present in request.input.body

Expected Behavior

I don't know if that's really a bug, but I had assumed that a POST endpoint using AJAX would still be usable for WS usages.

Current Behavior

Data is in different places, from the Kuzzle Request

Steps to Reproduce

  1. Create a custom Controller plugin with POST endpoint
  2. Send a payload to this POST endpoint with Ajax
  3. Create a Kuzzle.query to the same controller/action using Websocket

Context (Environment)

Docker instances Kuzzle 1.2.9

scottinet commented 6 years ago

This is not a bug: HTTP is very peculiar, and implicit body is a purely HTTP thing. This behavior is not applicable to any other protocol. If you need your payload property to be in the body part of a Request object using a non-HTTP protocol, then you need to send the following data: {body: {payload: {}} Any other property at the root of the sent data will be treated as extra arguments, and thus stored in the request.input.args part of a request.

So here Kuzzle behaves as expected.

On the other hand, to have these extra arguments with HTTP, you need to pass them in the URL.

You may check our documentation about standard requests syntax: https://docs.kuzzle.io/api-documentation/query-syntax/common-attributes/