RESTp - Output Formats RESTp supports json, xml and html as output data type

You can set the format of data received as output. Currently it supports, json, xml and html(table format). You can set header accept type to define the format of data to be received. Default format of data can be set in config.

You can set header Accept: as application/json, text/html or application/xml. Different languages has different ways of setting this header value.

  
                                //init curl
                                $ch = curl_init();
                                // URL to be called i.e. end point to access resource. 
                                // e.g. Get all records of a database table name "orders".
                                curl_setopt($ch, CURLOPT_URL, "http://pdocrud.com/RESTP/api/orders/");
                                //set http headers for output
                                // output as json
                                curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json'));
                                // output as text/html
                                //curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: text/html'));
                                // output as xml
                                //curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/xml'));
                                //return as output instead of printing it
                                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                                //execute curl request
                                $result = curl_exec($ch);
                                //close curl connection
                                curl_close($ch);
                                //print result
                                print_r($result);
                            
  
                                jQuery(document).ready(function () {
                                    jQuery.ajax({
                                    url: "http://pdocrud.com/RESTP/api/orders/",
                                    dataType: 'json',
                                    //dataType: 'xml',
                                    //dataType: 'html',
                                    contentType: 'application/json',
                                    success: function (response) {
                                        console.log(response);
                                        jQuery("#js_output").text(response);
                                    }
                                });
                            });