A task was received - to create an API for the
scribbler.ru site that would allow third-party developers to work with site resources, write applications both inside, in the form of a swf file, and located outside the site, let's say a desktop application that can receive / send mail to users of the site.
Everyone knows that popular Russian projects (vkontakte.ru, mail.ru and any others) have their own API. For example, I began to master them and look at how they are implemented, and you know that each site writes an API as it pleases (as the developers consider correct), i.e. The API mail.ru and vkontakte.ru differ greatly in their architectures, roughly speaking, they are not similar, which, I think, makes life difficult for developers, first we write our own classes that work with the API, under vkontake, then we write our classes under mail.ru and etc.
The question arose: “But how did the“ foreign ”sites solve this problem?”
')
We go to twitter.com, go to the "API" section, we look, we read and we see "The Twitter API".
Go to facebook.com, go to the section “Developers-> documentation” and again see “The API uses a REST-like interface”.
Come on! What is this REST?
And here it is! REST describes the paradigm architecture for web applications that request and manipulate web resources using standard HTTP methods GET, POST, PUT and DELETE.
We all know what a SOAP service is, so REST is something similar, only simpler;).
Thanks to REST, we can access the methods of our site objects, passing parameters using GET and POST methods and receiving XML from the server in response. Ie, let's say we need to get information about the user, then we go to the address
... / api / user.getInfo? UserId = 10 , in response we will
receive XML with information about it, at this address you can clearly see that we call the user object and execute its getInfo method, the input parameter would be userId = 10, in PHP it would look like $ user-> getInfo (10).
Simply? Conveniently? And how!
Okay, enough already to talk about it, it's time to move on to the principle of implementation, imagining that the site is implemented on MVC architecture.
The API should have its own objects, you should not call the methods of objects that are used inside the site, for security reasons, I think everyone understands this.
So let's imagine that API objects are stored in their daddy inside the project, and a developer contacts the address
... / api / user.getInfo , then apiController is cut, starts checking if the user object exists with the getInfo method, if not , it returns XML with the error status, if it does, it creates this object, calls the required method, converts the returned data into XML and outputs it to the view.
Step by step it will look like this:

Thus, we get API on architecture similar to twitter and facebook API, which is structured, easy, and most importantly, it is convenient to develop and allows third-party application developers not to rack their brains on smoking by reading documentation, and it is easy to port applications to your projects.
The next time we continue the conversation about OAuth authorization, which allows you to not enter the username and password of the user to use the API.
So, now, the site
scribbler.ru has its own API, and if there are those who want to try it out in action, then we consider “Welcome!”, An objective criticism and valuable wishes, to be excellent!
API documentation can be found here
scribbler.ru/developers .
PS I tried to write as clearly as possible, the story about the development was invented and based on real events;)