Allowing access to data remotely via xml?
If I wanted to allow someone to access data so they can put it on their site could I just have them point to a script on my server that takes certain queries via the url and that script queries my database, then sends back 开发者_Go百科the data to the person requesting the script in an xml format? That would be a very basic api setup wouldnt it? There isnt a lot of data and not a lot of calls so not worried about it slowing down my site. I just wanted to know if that is a normal/basic way of creating an api?
What you described is basically a web service.
I'd suggest trying a RESTful API. It boils down to this: you provide certain URLs on your server for your clients. They invoke that URL and you send them information in some format (usually XML or JSON) that they can use for further processing.
Example: try going to this website:
http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=stackoverflow
You will receive this response:
{"responseData": {"results":[{"GsearchResultClass":"GwebSearch","unescapedUrl":"http://stackoverflow.com/","url":"http://stackoverflow.com/","visibleUrl":"stackoverflow.com","cacheUrl":"http://www.google.com/search?q\u003dcache:U1GC2GYOToIJ:stackoverflow.com","title":"\u003cb\u003eStack Overflow\u003c/b\u003e","titleNoFormatting":"Stack Overflow","content":"A language-independent collaboratively edited question and answer site for programmers."},{"GsearchResultClass":"GwebSearch","unescapedUrl":"http://stackoverflow.com/users/login","url":"http://stackoverflow.com/users/login","visibleUrl":"stackoverflow.com","cacheUrl":"http://www.google.com/search?q\u003dcache:4nkh8ecRZGUJ:stackoverflow.com","title":"Log In - \u003cb\u003eStack Overflow\u003c/b\u003e","titleNoFormatting":"Log In - Stack Overflow","content":"\u003cb\u003estackoverflow\u003c/b\u003e.com ■ api/apps ■ careers ■ serverfault.com ■ superuser.com \u003cb\u003e...\u003c/b\u003e"},{"GsearchResultClass":"GwebSearch","unescapedUrl":"http://blog.stackoverflow.com/","url":"http://blog.stackoverflow.com/","visibleUrl":"blog.stackoverflow.com","cacheUrl":"http://www.google.com/search?q\u003dcache:iqtvg9Ge1c0J:blog.stackoverflow.com","title":"Blog – Stack Exchange","titleNoFormatting":"Blog – Stack Exchange","content":"They seem to think that we only have 659000 visitors to \u003cb\u003estackoverflow\u003c/b\u003e.com \u003cb\u003e...\u003c/b\u003e"},{"GsearchResultClass":"GwebSearch","unescapedUrl":"http://en.wikipedia.org/wiki/Stack_overflow","url":"http://en.wikipedia.org/wiki/Stack_overflow","visibleUrl":"en.wikipedia.org","cacheUrl":"http://www.google.com/search?q\u003dcache:mWu8b0BQAmwJ:en.wikipedia.org","title":"\u003cb\u003eStack overflow\u003c/b\u003e - Wikipedia, the free encyclopedia","titleNoFormatting":"Stack overflow - Wikipedia, the free encyclopedia","content":"In software, a \u003cb\u003estack overflow\u003c/b\u003e occurs when too much memory is used on the call stack. The call stack contains a limited amount of memory, often determined at \u003cb\u003e...\u003c/b\u003e"}],"cursor":{"pages":[{"start":"0","label":1},{"start":"4","label":2},{"start":"8","label":3},{"start":"12","label":4},{"start":"16","label":5},{"start":"20","label":6},{"start":"24","label":7},{"start":"28","label":8}],"estimatedResultCount":"1410000","currentPageIndex":0,"moreResultsUrl":"http://www.google.com/search?oe\u003dutf8\u0026ie\u003dutf8\u0026source\u003duds\u0026start\u003d0\u0026hl\u003den\u0026q\u003dstackoverflow"}}, "responseDetails": null, "responseStatus": 200}
which is Google's results when you search for "Stackoverflow".
精彩评论