leart Posted April 7, 2009 Share Posted April 7, 2009 Hey, I've got an API which handle requests via HTTP POST/GET with parameters and it's response is formatted in XML. I need to build a Web application to interact with this kind of API and I wasn't sure how should such an approach be designed. To put my idea in the most simple terms - I figure there should be some kind of Ajax extension which upon a button press can send information to the API, get the response back in XML. Then this XML data should be parsed for displaying the result in a table format or some other kind. Could someone shed some light on this for me? Thanks. I was also interested to use existing frameworks for the PHP application (i.e: Symfony or others) or at least for the XML or AJAX part (prototype or others) to provide a solid base for the application to grow. What do you think? And are there solutions which provide a BSD-like or LGPL licensing? Regards, Quote Link to comment https://forums.phpfreaks.com/topic/152977-php-and-xml-api-interface-question-design/ Share on other sites More sharing options...
JonnoTheDev Posted April 7, 2009 Share Posted April 7, 2009 You can send the post/get data to the API via CURL. Then you require a parser to parse the XML response. This is quite simple. Read up on CURL and SimpleXML Quote Link to comment https://forums.phpfreaks.com/topic/152977-php-and-xml-api-interface-question-design/#findComment-803425 Share on other sites More sharing options...
leart Posted April 7, 2009 Author Share Posted April 7, 2009 You can send the post/get data to the API via CURL. Then you require a parser to parse the XML response. This is quite simple. Read up on CURL and SimpleXML Thanks for the quick reply. I understand that this isn't a gene-development task and it's rather simple but I am asking more for good advises on the "design" so that this application is easier to grow with time. Sending requests via CURL sounds somewhat a "quick-and-dirty" solution and it's not what I'm looking for. I am just reading about zend's Zend_Http_Client which I can make use of to send the request and with the XML response to feed it to an XML parser like the suggest SimpleXML for processing. I need more of a "design" input. For example, I was thinking of something like this for the Zend_Http_Client: [form.php]: this page displays the form, when the Submit button is pressed it triggers an ajax-based event which calls the performXMLQuery.php page with the forms' input elements [performXMLQuery.php] receives the query, makes the required POST/GET to the API, handles the response, processes the XML and returns the data to the form.php page back for displaying so it is something like: [form.php] <-> [performXMLQuery.php] <Sent:POST/GET, Recv: XML > [API] I'm also wondering if the performXMLQuery.php should return a formatted output like in an html table format or it should still return a XML itself or some other kind of data storage format for the form.php page to process and decide how it should display. (I haven't mention but the deployment will be based on Windows (WAMP) if that is of any issue) Quote Link to comment https://forums.phpfreaks.com/topic/152977-php-and-xml-api-interface-question-design/#findComment-803442 Share on other sites More sharing options...
JonnoTheDev Posted April 7, 2009 Share Posted April 7, 2009 Sending requests via CURL sounds somewhat a "quick-and-dirty" solution and it's not what I'm looking for Zend_Http_Client is basically CURL. The package has the same function. Why would you need the entire zend framework to make an HTTP request. This is so simple and is no way dirty. You are making a bit of a mountain out of a molehill. Process 1. User submits the form 2. Send the input via a HTTP POST/GET request to API url 3. Parse the XML response via SimpleXML 4. Act on response and display results to user Why do you need to even use AJAX for this? Most simple API's are called via GET/POST requests in whatever fashion, they simply return a response. If an API uses a WSDL then you would use SOAP to make the requests. Quote Link to comment https://forums.phpfreaks.com/topic/152977-php-and-xml-api-interface-question-design/#findComment-803643 Share on other sites More sharing options...
Maq Posted April 7, 2009 Share Posted April 7, 2009 Zend_Http_Client is basically CURL. The package has the same function. Why would you need the entire zend framework to make an HTTP request. This is so simple and is no way dirty. You are making a bit of a mountain out of a molehill. Unless this is going to be a bigger and more elaborate project in the future. Another alternative to parse the XML with PHP is with DOM and XPath. Good luck. Quote Link to comment https://forums.phpfreaks.com/topic/152977-php-and-xml-api-interface-question-design/#findComment-803655 Share on other sites More sharing options...
leart Posted April 22, 2009 Author Share Posted April 22, 2009 Zend_Http_Client is basically CURL. The package has the same function. Why would you need the entire zend framework to make an HTTP request. This is so simple and is no way dirty. You are making a bit of a mountain out of a molehill. Process 1. User submits the form 2. Send the input via a HTTP POST/GET request to API url 3. Parse the XML response via SimpleXML 4. Act on response and display results to user Putting cURL and the Zend module aside. To post the request I can simply use sockets but the data replied is a valid http response which means it would include the HTTP headers along with the XML document in the body. Is there an easy way to get the XML document in the response into a variable which I can later push into SimpleXML or some other library? Quote Link to comment https://forums.phpfreaks.com/topic/152977-php-and-xml-api-interface-question-design/#findComment-816183 Share on other sites More sharing options...
JonnoTheDev Posted April 22, 2009 Share Posted April 22, 2009 Is there an easy way to get the XML document in the response into a variable which I can later push into SimpleXML or some other library Not by using sockets! As stated use CURL. // setup curl parameters curl_setopt($ch, // etc // process and store response $xmlresponse = curl_exec($ch); $obj->simplexml_load_string($xmlresponse); Quote Link to comment https://forums.phpfreaks.com/topic/152977-php-and-xml-api-interface-question-design/#findComment-816314 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.