[prev in list] [next in list] [prev in thread] [next in thread] 

List:       mythtv-dev
Subject:    Re: [mythtv] json vs XML
From:       George Nassas <gnassas () mac ! com>
Date:       2013-08-18 2:51:17
Message-ID: 31345CD7-A451-4E84-A831-475F4DE59660 () mac ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


On 2013-08-17, at 10:28 AM, Joseph Mills wrote:

> I for one would hate to see the api just switched over to pure json.

There isn’t much value in this and besides there’s hardly any effort in supporting \
multiple return formats. It’s not like there is one function that implements \
/Video/GetVideoList for json callers and another one that does it for xml callers. \
Each phase of fulfilling a request is done by one generic piece of code which passes \
its work off to another generic piece until the result is ready for the caller.

For example /Video/GetVideoList places its resulting list in a binary data structure \
which gets passed off to a generic output routine. This routine uses a technique \
called “introspection” to examine what it has been given and pass on instructions to \
an xml writer or a json writer. With the video list it would see the first attribute \
is called “StartIndex” and it’s an integer so the json writer would get instruction \
to write “StartIndex” : 0, later it would see an attribute VideoMetadataInfos which \
is an array so it would write “VideoMetadataInfos” : [ and so on until the entire \
data structure has been output.

With this architecture when someone adds a new service endpoint they only code the \
binary data loading part and their routine will automatically know how to render xml, \
soap or json. Similarly, if the myth people wanted to support a new language or \
format, like lisp, it would be a matter of creating a new backend for the \
introspection function and voila all the service apis would magically support that \
new format.

One routine to look up the requested data, one routine to introspect it and one \
routine for each possible return format: that’s the smart way to do it.

> As there are many their party apps that use json. Maybe if there was a way to call \
> the one you want to use example. Http://<yourbackend>:6544/foo?type=XML


Besides the path that you see (“foo?type=XML”) http also has something which appears \
in requests but users don’t typically see called “headers”. There’s a header called \
“Accept” which tells the server what format you want back. Giving “application/json” \
for the accept header tells the backend that you want your reply to be in json \
format. Soap and xml are also supported with xml as the default if you don’t send an \
accept header.

This is all standard stuff and is familiar to folks who noodle around with web \
services on a regular basis.

- George


[Attachment #5 (unknown)]

<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; \
-webkit-line-break: after-white-space; "><div><div>On 2013-08-17, at 10:28 AM, Joseph \
Mills wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><span \
class="Apple-style-span" style="border-collapse: separate; font-family: Helvetica; \
font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: \
normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; \
text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; \
-webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; \
-webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; \
-webkit-text-stroke-width: 0px; font-size: medium; ">I for one would hate to see the \
api just switched over to pure json.</span></blockquote><div><br></div><div>There \
isn’t much value in this and besides there’s hardly any effort in supporting multiple \
return formats. It’s not like there is one function that implements \
/Video/GetVideoList for json callers and another one that does it for xml \
callers.&nbsp;Each phase of fulfilling a request is done by one generic piece of code \
which passes its work off to another generic piece until the result is ready for the \
caller.</div><div><br></div><div>For example /Video/GetVideoList places its resulting \
list in a binary data structure which gets passed off to a generic output routine. \
This routine uses a technique called “introspection” to examine what it has been \
given and pass on instructions to an xml writer or a json writer. With the video list \
it would see the first attribute is called “StartIndex” and it’s an integer so the \
json writer would get instruction to write “StartIndex” : 0, later it would see an \
attribute VideoMetadataInfos which is an array so it would write “VideoMetadataInfos” \
: [ and so on until the entire data structure has been \
output.</div><div><br></div><div>With this architecture when someone adds a new \
service endpoint they only code the binary data loading part and their routine will \
automatically know how to render xml, soap or json. Similarly, if the myth people \
wanted to support a new language or format, like lisp, it would be a matter of \
creating a new backend for the introspection function and voila all the service apis \
would magically support that new format.</div><div><br></div><div>One routine to look \
up the requested data, one routine to introspect it and one routine \
for&nbsp;each&nbsp;possible return format: that’s the smart way to do \
it.</div><br><blockquote type="cite"><span class="Apple-style-span" \
style="border-collapse: separate; font-family: Helvetica; font-style: normal; \
font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: \
normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; \
white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: \
0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; \
-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; \
">As there are many their party apps that use json. Maybe if there was a way to call \
the one you want to use example. \
Http://&lt;yourbackend&gt;:6544/foo?type=XML<br></span></blockquote></div><div><br></div><div>Besides \
the path that you see (“foo?type=XML”) http also has something which appears in \
requests but users don’t typically see called “headers”. There’s a header called \
“Accept” which tells the server what format you want back. Giving “application/json” \
for the accept header tells the backend that you want your reply to be in json \
format. Soap and xml are also supported with xml as the default if you don’t send an \
accept header.</div><div><br></div><div>This is all standard stuff and is familiar to \
folks who noodle around with web services on a regular basis.</div><br><div>- \
George</div></body></html>



_______________________________________________
mythtv-dev mailing list
mythtv-dev@mythtv.org
http://www.mythtv.org/mailman/listinfo/mythtv-dev


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic