Commit 9fc7cb87 authored by Rafael Ostertag's avatar Rafael Ostertag
Browse files

Initial draft of PROTOCOL.md

parent 61abdb25
......@@ -2,22 +2,18 @@
# Client/Server Protocol
## Form initial call
## General Protocol
Request: index.php (QuickFormQuery.php, included by Typo3 extension)
Response:
Form attributes:
data-hidden: 'yes'|'no' - yes: The element is not visible yet, maybe later.
data-disabled: 'yes'|'no' - yes: The element is visible, but the user can't interact with it.
data-required: 'yes'|'no' - yes: The element is required. The form can't be submitted if any required element is empty.
The Client may asynchronously send requests to the Server. The Server
is expected to return responses as outlined below.
The response must contain at least a [Minimal Response]. Depending on
the request, it may provide additional responses as outlined in this
section.
## General Protocol
###
### Minimal Response
Asynchronous request (read AJAX) initiated by the Client receive a
JSON Response from the server containing at least:
......@@ -35,11 +31,13 @@ the server (`"success"`) or encountered an error (`"error"`). On
Depending on the request, the server may provide additional
information in the response, as outlined below.
### HTML Form Element Validation
The Server may perform a serverside validation of values submitted. If
the validation fails, it may notify the Client by adding following
name/value pairs to the response JSON Stream
### HTML Form Element Validation Response
The Server may perform a serverside validation of values submitted as
part of a HTML Form submission. If the validation fails, it may notify
the Client by adding following name/value pairs to the response JSON
Stream
{
"status": "error",
......@@ -52,8 +50,8 @@ name/value pairs to the response JSON Stream
Only one validation failure per request can be reported to Client.
The Server is expected to set the status `"status"` to `"error"`, and
the Client is expected to treat the error as explained in [General]
and must obey the rules of redirection as explained in [Redirection].
the Client is expected to treat the error as explained in [Minimal Response]
and must obey the rules of redirection as explained in [Redirection Response].
The Client must visibly highlight the HTML Form Element that caused the
validation failure.
......@@ -64,12 +62,15 @@ validation failure.
`"field-message"`
: Message to the User, indicating the nature of the failure.
### Form Group Configuration
### Form Group Configuration Response
As part of the server response, the JSON stream may contain a key
`form-update`. It contains an array of objects having the following
structure
`form-update`. This response is used to reconfigure HTML Form Elements
and Form Groups on the clientside, based on conditions evaluated on
the serverside. It contains an array of objects
having the following structure
{
...
......@@ -86,7 +87,6 @@ structure
...
}
`"form-element"`
: the name of the HTML Form Element as it appears in the `name` attribute.
......@@ -100,13 +100,16 @@ structure
: whether or not the Form Element receives the HTML5 `required` attribute.
`"value"`
: For textual HTML Form Input elements, it is supposed to be a scalar value, which is set on the element.
: For textual HTML Form Input elements, it is supposed to be a scalar
value, which is set on the element.
When `"form-element"` references a `<select>` element, a scalar value
selects the corresponding value from the option list. In order to replace
the entire option list, use an array of objects, having this format
When `"form-element"` references a `<select>` element, a scalar
value selects the corresponding value from the option list. In
order to replace the entire option list, use an array of objects
as value to `"value"`, having this format
[
...
{
"value": 100,
"text": "a",
......@@ -117,6 +120,7 @@ structure
"text": "b",
"selected": false
}
...
]
`"select"` is optional, as is `"text"`. If `"text"` is omitted, it
......@@ -129,10 +133,10 @@ structure
radio button `value`-attribute to be activated in `"value"`.
### Redirection
### Redirection Response
Depending on the request, the server may return redirection
information to Client. It is up to the Client to respect the
information to the Client. It is up to the Client to respect the
redirection information.
The Client must not perform a redirect in case the status in
......@@ -157,22 +161,12 @@ The format of redirect information is outlined below
`"redirect-url"`
: Used to provide an URL when `"redirect"` is set to `"url"`. It
should be disregarded unless `"redirect"` is set to `"url"`.
## Form Update
Request URL
: api/load.php
Request Method
: POST
## API Endpoints
URL Parameters
: none
Server Response
: The response contains
### Form Update
The Client may request an updated set of Form Group Configuration and
HTLM Element states. In order for the Server to compile the set of
......@@ -180,126 +174,106 @@ Form Group Configuration and HTML Element states, it requires the
entire HTML Form in the POST body, without any HTML Input Elements of
type `file`.
The Client must include the SIP using an HTML Input Element (most likely of `type` `hidden`).
The Client must include the SIP using an HTML Input Element (most
likely of `type` `hidden`).
Request URL
: api/load.php
Form save
---------
### Trigger
none
Request Method
: POST
### Request: api/save.php
URL Parameters
: none
#### Type
POST
Server Response
: The response contains at least a [Minimal Response]. In addition,
a [Form Group Configuration Response] may be included.
#### Parameters
##### URL
none
### Form Save
##### POST
HTML Form without `<input>` elements of type `file`. The HTML Form is required to have a HTML Form Element named `s`, which must contain the SIP.
The Client submits the HTML Form for persitent storage to the
Server. The submission should not contain `<input>` HTML Elements of
type `file`.
### Response
The Client must include the SIP using an HTML Input Element (most
likely of `type` `hidden`).
JSON Stream
Request URL
: api/save.php
{
"status": "success"|"error",
"message": "<message>",
"redirect": "client"|"url"|"no",
"field-name": "<field name>",
"field-message": "<message>",
"form-update": [
{
"form-element": "<element_name>",
"hidden": true | false,
"disabled": true | false,
"required": true | false,
"value": <value>
}
]
}
Request Method
: POST
Name | Description
------- | -----------
status | see General
message | see General
redirect | not used
field-name | HTML Form Element Name which raised error on server side. Requires status to be `"error"`
field-message | reason of error. Requires status to be `"error"`.
form-update | Array of Objects. Each object describes the state and value of a HTML Form Element identfied by its `name` attribute.
URL Parameters
: none
Server Response
: The response contains at least a [Minimal Response]. In addition, a
[Form Group Configuration Response],
[HTML Form Element Validation Response] and/or
[Redirection Response] may be included.
File (upload)
-------------
### Trigger
none
### File Upload
### Request: api/file.php
Files are uploaded asynchronously. Each file to be uploaded requires
one request to the Server, using a Multi part form with file content,
parameter `s` containing SIP, and parameter `name` containing the name
of the HTML Form Element.
#### Type
POST
Request
: api/file.php
#### Parameters
Request Method
: POST
##### URL
`action=upload`
URL Parameters
: `action=upload`
##### POST
Multi part form with file content, parameter `s` containing SIP, and parameter `name` containing the name of the HTML Form Element.
Server Response
: The response contains a [Minimal Response].
### Response
JSON Stream
### File Delete
{
"status": "success"|"error",
"message": "<message>"
}
Files are delete asynchronously. Each file to be delete on the
serverside requires on request to the Server. The parameters
identifying the file to be deleted are sent as part of the POST
body. The SIP of the request is included in the parameter name
`s`. The value of the `name` attribute of the HTML Form Element is
provided in `name`.
Request
: api/file.php
Name | Description
------- | -----------
status | see General
message | see General
Request Method
: POST
URL Parameters
: `action=delete`
Record delete
-------------
Server Response
: The response contains a [Minimal Response].
Request: api/delete.php
### Record delete
Return JSON encoded answer
Request the deletion of the record identified by the SIP.
status: success|error
message: <message>
redirect: client|url|no
redirect-url: <url>
field-name:<field name>
field-message: <message>
Request
: api/delete.php
Description:
Request Method
: POST
Delete successfull.
status = 'success'
message = <message>
redirect = 'client'
URL Parameters
: `s=<SIP>`
Delete successfull.
status = 'success'
message = <message>
redirect = 'url'
redirect-url = <URL>
Server Response
: The response contains a [Minimal Response].
Delete failed: Show message.
status = 'error'
message = <message>
redirect = 'no'
## Glossary
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment