Specifications Understanding the specification notation Building blocks Common building blocks Description object database Additional building blocks Specification Descriptions Request object Specification Response object Specification Fault response object Additional building blocks Specification Descriptions
Real-world example Description Service call 1 Request Response Service call 2 Request Response
Attachments Attachment service description example Attachment service request example
Server implementations
Client implementations
See also
References
[https://en.wikipedia.org/w/index.php?oldid=757972316 This article] is on hold (will be deleted), perhaps you are searching for JSON-RPC or JSON Schema.
JSON-WSP (JavaScript Object Notation Web-Service Protocol) is a web-service protocol that uses JSON[1] for service description, requests and responses. It is inspired from JSON-RPC, but the lack of a service description specification with documentation in JSON-RPC sparked the design of JSON-WSP.
The description format has the same purpose for JSON-WSP as WSDL has for SOAP or IDL for CORBA, which is to describe the types and methods used in a given service. It also describes inter-type relations (i.e. nested types) and defines which types are expected as method arguments and which types the user can expect to receive as method return values. Finally the description opens the possibility to add documentation on service, method, parameter and return levels.
Communication between clients and a JSON-WSP server is carried out using HTTP POST[2] requests and responses, with the JSON objects as data with the content-type application/json.[3]
Specifications
JSON-WSP consists of four JSON object specifications:
Specification
Description
description
Service description specification (like WSDL). This specification describes methods, method parameters, types and return types. It also supports user documentation on service, method and parameter levels.
request
Specification for JSON requests. It contains information about which method that is to be invoked and all the arguments for the method call. Arguments in the request must obey the parameter definition of the same method described in the corresponding JSON-WSP description.
response
Specification for JSON responses. The response object contains the result of a service method invocation. The return type must obey the defined return type of the same method in the corresponding JSON-WSP description.
fault
Specification for JSON fault responses. The fault object contains a fault code and a fault string. The fault information specifies whether the fault occurred on the client or server side. Depending on the server side service framework more detailed information can be extracted, i.e. the filename and line number where the fault occurred.
NOTE: JSON-WSP specification 1.0 is still{{When|date=July 2012}} not final. Please refer to the real-world example in this article to get an idea of how the specification is going to be structured. The current state of the actual specification is kept at launchpad.net:.[4] An RFC proposal is currently being created and hopefully accepted within a couple of months.{{When|date=July 2012}}
Understanding the specification notation
Building blocks
If the name of the building block being defined starts with rx-, it means that the definition is a regular expression. In these definitions square brackets have the role of defining character classes and parentheses have the role of defining capturing groups.
In all other cases, square brackets notate lists and parentheses notate either a decision:{{sp?|date=October 2011}}:
( d1 | d2 | ... )
a repetition of 0-many:
( ... )
a repetition 1-many:
( ... )+
or something optional:
( ... )?
Common building blocks
Description object database
Additional building blocks
Specification
Descriptions
:
The service endpoint URL that accepts JSON-WSP POST request objects.
:
Service name is case sensitive. It identifies a specific service exposed on a specific server.
doc_lines:
Each doc-string contained in a doc_lines list reflects a single line of documentation that relates to the parent object of the doc_lines..
Request object
The request object contains information about which method to invoke and what arguments to invoke the method with. It also stores information about the type and version of itself.
The optional mirror value can be used to send information from the client which will then be reflected by the server and returned unchanged in the response object's reflection value. This feature allows clients to send multiple requests to a method and send request identification values that can be intercepted by the client's response handler. This is often necessary from javascript if more than one request is being processed simultaneously by the server and the response order is unknown by the client.
Specification
Response object
Specification
The reflection value is an unchanged server reflection of the request object's mirror value. It is marked as optional because it is the client that controls via the request whether it is there or not.
Fault response object
Additional building blocks
Specification
Descriptions
:
The meanings of the possible fault-codes:
"incompatible": Client version of JSON-WSP is incompatible with the server version of JSON-WSP. Typically one will encounter this type of fault-code if there is a version major in difference between the client and the server.
"server": An error occurred on the server side after the client request has been successfully consumed.
"client": The clients request could not be consumed by the server due to incorrect format or missing required arguments etc.
Real-world example
Description
Service call 1
Request
Response
Service call 2
Request
Response
Attachments
The attachment type is new in JSON-WSP. It can be used anywhere in the description as a primitive type. In requests and responses that involve attachments, the message format must be multipart/related where the attachments are transported as mimeparts of media type: application/octet-stream with no Content-Transfer-Encoding (only raw binary). Mimeparts must have a unique CONTENT-ID in their entity headers. Attachment values in the JSON-WSP request/response objects must match the regular expression "^cid:(.+)$" where the capture group maps to one of the mimepart's CONTENT-ID.
Attachment service description example
The following example shows what a simple JSON-WSP description with attachments could look like:
Attachment service request example
A request to the method "upload" described above could look like this:
Server implementations
ladon at PyPI Ladon is a Python-based framework that exposes json-wsp and other protocols
ladon at ladonize.org ladonize.org is the official homepage for ladon. It contains running demos.
[https://bitbucket.org/pfacka/jsonwsp pfacka/jsonwsp] A Python JSON-WSP server implentation]