Development/ws/js: Difference between revisions

From MusicBrainz Wiki
Jump to navigationJump to search
Line 10: Line 10:
* page allows you to select the page, if there are more than <i>limit</i> results (optional)
* page allows you to select the page, if there are more than <i>limit</i> results (optional)


The services provide a JSON formatted response which contains a list of search results. Note that the final entry of the list is not a search result, but information about the search itself.
The services provide a JSON formatted response which contains a list of search results. The final entry of the list is not a search result, but information about the search itself, so pop this off the list if you're only interested in the results themselves.


A response looks like this:
A response looks like this:

Revision as of 13:18, 20 October 2010

Autocomplete

Currently there is an autocomplete interface for artists and labels. A request looks like this:

 /ws/js/artist?q=cycles&limit=3&page=1
 /ws/js/label?q=warp+records
  • q is the search term
  • limit is the max number of results on a page (optional)
  • page allows you to select the page, if there are more than limit results (optional)

The services provide a JSON formatted response which contains a list of search results. The final entry of the list is not a search result, but information about the search itself, so pop this off the list if you're only interested in the results themselves.

A response looks like this:

[
   {
       "comment": null, 
       "gid": "3c4524ce-dc16-4dbd-b52f-6e7f9f067f9a", 
       "name": "7 Cycles", 
       "id": "556345"
   }, 
   {
       "comment": "UK Based Electronica Producer Oliver Charles", 
       "gid": "d3423ede-83ba-4758-8e4c-4f0d5f0bfabd", 
       "name": "Cycles", 
       "id": "592771"
   }, 
   {
       "comment": null, 
       "gid": "8847a88f-5780-4224-b879-8dc15ce153a0", 
       "name": "Pharmakustik + Frequency in Cycles Per Second", 
       "id": "650671"
   }, 
   {
       "current": "1", 
       "pages": 2
   }
]

NOTE: there is also a seperate recording autocomplete lookup, but this isn't documented yet as it is scheduled to undergo some changes to share more code with the label/artist lookups.

Tracklist

I think I want to render disc format and title as part of the collapsed discs, so they don't need to be included in a /ws/js call for the tracklist tab. If I also include the tracklist id when rendering the collapsed discs, I can just call:

 /ws/js/tracklist/<tracklist-row-id>

And the response should be something like this (this example contains just one track, a typical tracklist will obviously have more tracks as part of the top-level array):

[
    {
       "length": "4:03",                  # track length, preferably already formatted.
       "title": "the Love Bug"            # track title.
       "artist": {
           "preview": "m-flo\u2665BoA", 
           "names": [
               {
                   "credit": "m-flo", 
                   "gid": "22dd2db3-88ea-4428-a7a8-5cd3acf23175", 
                   "join": "\u2665", 
                   "name": "m-flo"
               }, 
               {
                   "credit": "BoA", 
                   "gid": "a16d1433-ba89-4f72-a47b-a370add0bb55", 
                   "join": null, 
                   "name": "BoA"
               }
           ]
       }, 
    }
]


further notes:

  • the artist/recording lookups may use the external search, which uses GIDs instead of row ids, so for consistency it seems better to not use row ids in these json responses.
  • including the artist credit preview isn't technically neccesary, we have code in javascript anyway to render artist credits, so you can leave it off if you prefer.
  • if you want to name certain keys differently because of consistency with the database or the perl code, be my guest.