API (Application Programming Interface)

Well… Don’t blame me, but I have to write this…

The answer is yes, but another question is if you should? :]

As you admitted yourself, you are only started learning Web Development and Yii and you already want to develop whole social network? That seems to be a kind of huge, really huge work (especially for just one developer) and I’m thinking, if you are not to fast? Wouldn’t be easier for you to write first something easier like a blog or sth? You know, social networks are (by definition) pages being used by thousand of people, where even smallest mistake (especially in security area) can ruin whole project and make you really a lot of troubles.

Don’t get me wrong, I believe you are a fast learning person and I wish you the best. But you’re aiming in a really big adventure and I wish it wouldn’t be to big for you. I know quite a few people here that has Yii coding experience year or longer, PHP and Website development experience counted in many years and still wouldn’t take such a task like develop social network just by a one person.

And you admitted yourself, you are only started learning Web Development and Yii…

It’s certainly possible. There’s the http://www.yiiframework.com/doc/api/1.1/CWebService/ if you want to go that route, or you can use the curl Extension that was recently posted of Jacmoe’s REST that is shown here …

Generally speaking, I’m pretty convinced that if you can think of it (ESPECIALLY if it’s something that already exists elsewhere), you can build it ;) Some things are just a little more complicated to accomplish than others.

Well, I am “forced” to implement an API for my Yii powered issue tracker, so there will be ‘something’.

Most probably REST, but maybe XMLRPC / JSONRPC. We’ll see.

It depends on my projects needs.

It’s definitely possible. :)

Someone made a REST implementation for Code Igniter, so there should be one for Yii. Obviously.

Can someone give me an example of REST and SOAP operations, and what the difference is between them? I don’t really get the concept of these Web APIs or whatever, sorry I’m a noob just curious. Thanks.

I was going to cook up an answer, but then I noticed this page:

http://en.wikipedia…_State_Transfer

But REST is so easy when you’re using a modern (web 2.0 - Ruby on Rails inspired) framework.

Like Yii.

http://localhost/post/update/5 is a REST-full url.

Normally it returns html to the browser renderer, but it can also return xml, json, whatever.

And if you have an API, you can operate on that url, perform an action, not always from a browser, but also from a desktop app.

Like an old proverb saying that the only thing impossible is to piss toward rain and remain dry! :] (sorry) But, on the other hand, as samdark replied in one of my topics, there are a few things in Yii that still need to be implemented. But… it is good to know that there aren’t many! :}

I am another person that would personally be very interested in such reading. Maybe someone can give as some tip on good reading, not sending us to old good uncle Google (right, Mike? :]) And maybe someone would be interested in writing a short cookbook article about it?

Basically REST is about performing four different kinds of actions on an url (resource).

SOAP returns an object which you are free to abuse perform operations on.

It’s XML so maybe slightly ineffective for large objects.

REST is awfully simple. And effective.

There is no standard as it’s an arcitecture rather than a standard.

So you can do anything, and return exactly what the caller asks for: xml, json, plain text, yiddish…

Facebook API, Twitter API, Atom, blah - all rest-ful apis.

This REST is what makes it possible to write those nifty desktop apps you can use to read and post Tweets (Twitter) and/or update your blog from your desktop.

Or, what I need: to use TortoiseHg to fetch the list of outstanding issues and reference/close/fix them by commit messages (issue browser).

XML-RPC is the predecessor to SOAP.

(I didn’t know that until reading it on Wikipedia).

And it’s a lot simpler than SOAP (obviously).

REST is even simpler due to Yii’s CRUD which maps directly to the four different types of REST actions: GET, PUT, POST, DELETE.


GET == index/view.

PUT == update

POST == create

DELETE == delete

Hey jacmoe,

great job, I think that’s exactly what I need. To be straightforward - I’m absolutely new to this, but I still need to write some kind of REST interface…

So, what I did is:

  1. copied your code (class RestRequest) to a new file protected\components\RestRequest.php

  2. added the “‘resources’ => array(‘post’, ‘page’)” to my config\main.php

  3. ran the code you provided …

But then I get an error

"Fatal error: Call to undefined function curl_init() in C:\xampp\htdocs\iDispatch\protected\components\RestRequest.php on line 44"

  • I think I have missed something or have done something wrong… Can you help me…?

Thanks a lot and greetings from Germany

Daniel

I know it is more than a year after this was posted, but you will get this error if you do not have the php_curl extension installed on your web server. Hope this helps someone.