开发者

Setup XML Web Service Request

I am runningn PHP and MySQL on a server and want to provie a web service of product information and having searched Google not sure best place to start and if anyone would know where I can fin开发者_如何转开发d some sample code or easy to undertand examples.

I will have about 30 items they can query for example. the dep will be the department and Count will be how many records to return.

BrandName Price ShortDescription SKU

The request will be made over http://website.com/productxml?dep=1&Count=3&BrandName=Y&Price=Y.

If anyone knows any good resources or has some sample code this would be much appreciated.

Thanks Roy


As @lbu suggests you could dynamically create the XML using PHP and data from your database (don't forget to set the headers!).

I was searching for a solution to create a small API for a webservice without too much hussle and I came across Luracast Restler. It's a free PHP solution that let's you create an API in no time. Keep in mind that it's still in production, but it does work rather well already. (If made a few fixes and I'll suggest these to them soon). You can download it from their GitHub project page and it includes some examples to get you started.


You can use JSON encoded Object/Array:

header('Cache-Control: no-cache, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Content-type: application/json');

echo json_encode($data);

But before that you need to parse the request and do checks on the variable, maybe escape them to preven any malisios data input or request. I suppose you'll need some simple API that will provide the access to the database. You can create your own class, something like class ProductsService {}

after that depending on the request items in the GET return different data.

Here are two examples:

Zend Framework Service Class

PHP Soap Server class

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜