Roy
Roy

Reputation: 1

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 find 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

Upvotes: 0

Views: 328

Answers (2)

Arno Moonen
Arno Moonen

Reputation: 1194

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.

Upvotes: 1

Alex Rashkov
Alex Rashkov

Reputation: 10015

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

Upvotes: 0

Related Questions