Rest vs Rpc

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • aubergine
    Junior Member
    • Jan 2010
    • 19

    #1

    Rest vs Rpc

    From my quick tests it looks like the API here:

    https://beta-api.betfair.com/rest/v1.0/

    accepts a JSON request but returns XML - is that correct?


    The API here:

    https://beta-api.betfair.com/json-rpc/

    accepts JSON and returns JSON.

    Other than the verbosity of XML, are there any other reasons to prefer one over the other?

    I'm using C# and .NET.
  • AlgoTrader
    Junior Member
    • Mar 2012
    • 243

    #2
    That's not clear, whether REST API will come along with JSON-RPC. I see lots of activity in JSON-RPC and nothing in REST. I have no clear vision whether they go with two APIs or JSON-RPC will push REST out.

    I would bet on JSON-RPC as it allows to forget XML
    Betfair Bots Made Easy

    Comment

    • AlgoTrader
      Junior Member
      • Mar 2012
      • 243

      #3
      The things are much more funny. Sometimes REST returns XML, sometimes JSON. Supposedly, Betfair wants to calm down XML fans. Have a look:

      JSON answer:
      $ curl -v https://beta-api.betfair.com/rest/v1.0
      * About to connect() to beta-api.betfair.com port 443 (#0)
      * Trying 84.20.200.218...
      * connected
      * Connected to beta-api.betfair.com (84.20.200.218) port 443 (#0)
      * Initializing NSS with certpath: sql:/etc/pki/nssdb
      * CAfile: /etc/pki/tls/certs/ca-bundle.crt
      CApath: none
      * SSL connection using SSL_RSA_WITH_RC4_128_MD5
      * Server certificate:
      * subject: CN=*.betfair.com,OU=IS,O=The Sporting Exchange Ltd,L=London,ST=United Kingdom,C=GB
      * start date: Dec 28 00:00:00 2012 GMT
      * expire date: Dec 29 23:59:59 2013 GMT
      * common name: *.betfair.com
      * issuer: CN=VeriSign Class 3 Secure Server CA - G3,OU=Terms of use at https://www.verisign.com/rpa (c)10,OU=VeriSign Trust Network,O="VeriSign, Inc.",C=US
      > GET /rest/v1.0 HTTP/1.1
      > User-Agent: curl/7.24.0 (x86_64-redhat-linux-gnu) libcurl/7.24.0 NSS/3.13.5.0 zlib/1.2.5 libidn/1.24 libssh2/1.4.1
      > Host: beta-api.betfair.com
      > Accept: */*
      >
      < HTTP/1.1 404 Not Found
      < Date: Thu, 31 Jan 2013 14:27:48 GMT
      < Cache-Control: no-cache
      < Content-Type: application/json
      < Content-Length: 59
      <
      * Connection #0 to host beta-api.betfair.com left intact
      {"detail":{},"faultcode":"Client","faultstring":"D SC-0021"}* Closing connection #0
      XML answer:
      $ curl -v -H "Accept: xml" https://beta-api.betfair.com/rest/v1.0
      * About to connect() to beta-api.betfair.com port 443 (#0)
      * Trying 84.20.200.218...
      * connected
      * Connected to beta-api.betfair.com (84.20.200.218) port 443 (#0)
      * Initializing NSS with certpath: sql:/etc/pki/nssdb
      * CAfile: /etc/pki/tls/certs/ca-bundle.crt
      CApath: none
      * SSL connection using SSL_RSA_WITH_RC4_128_MD5
      * Server certificate:
      * subject: CN=*.betfair.com,OU=IS,O=The Sporting Exchange Ltd,L=London,ST=United Kingdom,C=GB
      * start date: Dec 28 00:00:00 2012 GMT
      * expire date: Dec 29 23:59:59 2013 GMT
      * common name: *.betfair.com
      * issuer: CN=VeriSign Class 3 Secure Server CA - G3,OU=Terms of use at https://www.verisign.com/rpa (c)10,OU=VeriSign Trust Network,O="VeriSign, Inc.",C=US
      > GET /rest/v1.0 HTTP/1.1
      > User-Agent: curl/7.24.0 (x86_64-redhat-linux-gnu) libcurl/7.24.0 NSS/3.13.5.0 zlib/1.2.5 libidn/1.24 libssh2/1.4.1
      > Host: beta-api.betfair.com
      > Accept: xml
      >
      < HTTP/1.1 404 Not Found
      < Date: Thu, 31 Jan 2013 14:27:54 GMT
      < Cache-Control: no-cache
      < Content-Type: application/xml
      < Content-Length: 126
      <
      * Connection #0 to host beta-api.betfair.com left intact
      <?xml version='1.0' encoding='utf-8'?><fault><faultcode>Client</faultcode><faultstring>DSC-0021</faultstring><detail/></fault>* Closing connection #0
      Betfair Bots Made Easy

      Comment

      • Mr Magoo
        Junior Member
        • Jan 2011
        • 86

        #4
        Is that not just because of the 404 Not Found error?

        If the server can't find the API code, you can't rely on the 404 response being generated by the API code.

        Comment

        • aubergine
          Junior Member
          • Jan 2010
          • 19

          #5
          No I don't think so. This call to Rpc

          POST https://beta-api.betfair.com/json-rpc HTTP/1.1
          X-Application: ---
          X-Authentication: ---
          Content-Type: application/json; charset=utf-8
          Host: beta-api.betfair.com
          Content-Length: 122
          Expect: 100-continue

          {"jsonrpc": "2.0", "method": "SportsAPING/v1.0/listCompetitions", "params": {"filter":{ "eventTypeIds" : [1] }}, "id": 1}
          returns:

          HTTP/1.1 200 OK
          Date: Thu, 31 Jan 2013 16:23:04 GMT
          Cache-Control: no-cache
          Content-Type: application/json
          Content-Length: 9148

          {"jsonrpc":"2.0","result":[{"competition":{"id":"67721","name":"Finnish League Cup"},"marketCount":125},{"competition":{"id":"833 222","name":"Turkish Division 2"},"marketCount":16}........
          But this call to rest:

          POST https://beta-api.betfair.com/rest/v1...tCompetitions/ HTTP/1.1
          X-Application: ---
          X-Authentication: ---
          Content-Type: application/json; charset=utf-8
          Host: beta-api.betfair.com
          Content-Length: 46
          Expect: 100-continue

          {"filter":{ "eventTypeIds" : [1] }}, "id": 1}
          returns this:

          HTTP/1.1 200 OK
          Date: Thu, 31 Jan 2013 16:22:51 GMT
          Cache-Control: no-cache
          Content-Type: application/xml
          Content-Length: 17136

          <?xml version='1.0' encoding='UTF-8'?><ListCompetitionsResponse xmlns="http://www.betfair.com/servicetypes/v1/SportsAPING/"><CompetitionResult><competition><id>67721</id><name>Finnish League Cup</name></competition><marketCount>125</marketCount></CompetitionResult><CompetitionResult><competition> <id>833222</id><name>Turkish Division 2</name></competition><marketCount>16</marketCount></CompetitionResult><CompetitionResult><competition> <id>744098</id><name>Chilean Primera</name></competition><marketCount>414</marketCount>.............

          Comment

          • AlgoTrader
            Junior Member
            • Mar 2012
            • 243

            #6
            Yes, it seems it was accident. I really messed with XML and JSON in REST, I think it should be clarified. The JSON request with XML answer is something that I never saw before.

            PS. I really wonder of how JSON is concise comparing to XML. No closing tags, no namespaces. Closing tags add 20-30% of text without any information inside
            Betfair Bots Made Easy

            Comment

            • aubergine
              Junior Member
              • Jan 2010
              • 19

              #7
              Well from my tests above, both calling 'listCompetitions', you can see the difference in the result size:

              Content-Type: application/json
              Content-Length: 9148

              versus

              Content-Type: application/xml
              Content-Length: 17136

              Comment

              • gus
                Senior Member
                • Jan 2009
                • 134

                #8
                Well, I'm using rest (in a Java application), and I don't see any XML

                Query:

                URL: https://beta-api.betfair.com/rest/v1.0/listEventTypes/ {"filter":{"eventTypeIds":[]}}

                Response:
                Code:
                [{"eventType":{"id":"468328","name":"Handball"},"marketCount":77},{"eventType":{"id":"1","name":"Soccer"},"marketCount":
                24806},{"eventType":{"id":"2","name":"Tennis"},"marketCount":585},{"eventType":{"id":"3","name":"Golf"},"marketCount":12
                0},{"eventType":{"id":"4","name":"Cricket"},"marketCount":264},{"eventType":{"id":"5","name":"Rugby Union"},"marketCount
                ":134},{"eventType":{"id":"6","name":"Boxing"},"marketCount":50},{"eventType":{"id":"7","name":"Horse Racing"},"marketCo
                unt":397},{"eventType":{"id":"8","name":"Motor Sport"},"marketCount":8},{"eventType":{"id":"7524","name":"Ice Hockey"},"
                marketCount":574},{"eventType":{"id":"10","name":"Special Bets"},"marketCount":65},{"eventType":{"id":"451485","name":"W
                inter Sports"},"marketCount":46},{"eventType":{"id":"7522","name":"Basketball"},"marketCount":424},{"eventType":{"id":"1
                477","name":"Rugby League"},"marketCount":80},{"eventType":{"id":"4339","name":"Greyhound Racing"},"marketCount":319},{"
                eventType":{"id":"6231","name":"Financial Bets"},"marketCount":51},{"eventType":{"id":"2378961","name":"Politics"},"mark
                etCount":21},{"eventType":{"id":"998917","name":"Volleyball"},"marketCount":80},{"eventType":{"id":"998918","name":"Bowl
                s"},"marketCount":47},{"eventType":{"id":"998920","name":"Floorball"},"marketCount":1},{"eventType":{"id":"26420387","na
                me":"Mixed Martial Arts"},"marketCount":23},{"eventType":{"id":"3503","name":"Darts"},"marketCount":127},{"eventType":{"
                id":"2152880","name":"Gaelic Games"},"marketCount":71},{"eventType":{"id":"6422","name":"Snooker"},"marketCount":22},{"e
                ventType":{"id":"6423","name":"American Football"},"marketCount":99},{"eventType":{"id":"7511","name":"Baseball"},"marke
                tCount":7}]

                Comment

                • MarkL
                  Junior Member
                  • Oct 2008
                  • 29

                  #9
                  Originally posted by aubergine View Post
                  No I don't think so. This call to Rpc



                  returns:



                  But this call to rest:



                  returns this:
                  Hi,

                  This is a bug in the developer preview. It will be fixed at some point.

                  It's probably triggered by calling the JSON endpoint with a JSON-RPC parameter : "{ 'id' : 1 }"

                  Thanks,
                  Mark

                  Comment

                  Working...
                  X