Yii Framework Forum: Restful Webservice - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Restful Webservice Rate Topic: ***** 1 Votes

#1 User is offline   Rodrigo Dias 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 26-September 12

Posted 03 October 2012 - 08:18 AM

Hi guys.

I want to build a webservice that returns xml.
As far as I know with soap you create a bunch of methods that do a lot of stuff, ignoring the type of request.

Is it possible to create a restful api that returns xml?
in this link : http://www.yiiframew...ate-a-rest-api/
he created an api using rest and returning json. And the method CJSON::encode to turns objects into json .
is there a method that takes an object and generates xml?

sorry im kind of lost.
0

#2 User is offline   jacmoe 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 2,601
  • Joined: 10-October 10
  • Location:Denmark

Posted 03 October 2012 - 09:10 AM

What do you need xml for ?
Just curious.
It's not very suited for the web, IMO.
"Less noise - more signal"
0

#3 User is offline   Rodrigo Coelho 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 665
  • Joined: 05-August 10
  • Location:Rio de Janeiro, Brazil

Posted 03 October 2012 - 09:17 AM

You are on the right track following that wiki for the REST part.

To generate the XML, you create your own views. Or maybe SimpleXML can help you.

Don't forget to set the proper XML response content-type using header.
0

#4 User is offline   Rodrigo Dias 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 26-September 12

Posted 03 October 2012 - 10:56 AM

hum, this webservice will provide xml for an iphone app.

View Postjacmoe, on 03 October 2012 - 09:10 AM, said:

What do you need xml for ?
Just curious.
It's not very suited for the web, IMO.

0

#5 User is offline   Rodrigo Dias 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 26-September 12

Posted 03 October 2012 - 11:31 AM

actually I need to convert active record objects to xml, im not sure if simpleXml does that, any hints?
0

#6 User is offline   Rodrigo Coelho 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 665
  • Joined: 05-August 10
  • Location:Rio de Janeiro, Brazil

Posted 03 October 2012 - 12:00 PM

It won't convert automatically, you'll have to manage the process by using its methods (like addChild).
If your models follow a predictable structure, you can write a class to do the conversion.
0

#7 User is offline   jacmoe 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 2,601
  • Joined: 10-October 10
  • Location:Denmark

Posted 04 October 2012 - 03:38 PM

I figured that this is such a common task, and it is, converting JSON to XML.

So here it is:
https://github.com/s.../class.json.php
"Less noise - more signal"
0

#8 User is offline   Rodrigo Dias 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 26-September 12

Posted 04 October 2012 - 09:41 PM

Thanks, thats what I need...
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users