Difference between revisions of "User:Bitmap/ws/js/template"

From MusicBrainz Wiki
(New page: This document details the proposed /ws/js/template endpoint. It is intended for use by the MusicBrainz JavaScript as a tool to render (relatively) small, reusable templates defined on the ...)
(No difference)

Revision as of 02:35, 5 June 2012

This document details the proposed /ws/js/template endpoint. It is intended for use by the MusicBrainz JavaScript as a tool to render (relatively) small, reusable templates defined on the server. Templates can therefore be shared for both server and client rendering needs.

Syntax

Requests should be sent to the URL

 /ws/js/template/{name}

which fetches the template with name {name}.

The available template names are hardcoded, and correspond to a single template file in the mbserver root.

Variables are sent to the template by HTTP POST, in JSON format. The outermost type in the document must be an array of objects, with each object representing a separate rendering request. This allows the endpoint to render multiple instances of the template in a single POST.

Example

(Not a real example.)

 POST /ws/js/template/track HTTP/1.1
 
Content-Type: application/json; charset=utf-8
 
 [
   {
     "position": "1",
     "name": "Part Company",
     "length": "4:54",
     "artist": "The Go-Betweens"
   },
   {
     "position": "2",
     "name": "Just a King in Mirrors",
     "length": "2:58",
     "artist": "The Go-Betweens"
   }
 ]

Response

If the request is OK, the response will contain a JSON array of rendered HTML fragments (strings). The order of the fragments will be the same as the argument objects' order in the initial request.

Other possible responses are listed below.

  • 400 - The JSON sent was malformed/could not be parsed.
  • 404 - There is no template with name {name}.

Example

(Not a real example.)

 [

" 1 Part Company The Go-Betweens 4:54 ", " 2 Just a King in Mirrors The Go-Betweens 2:58 " ]

Available Templates

None yet.