New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[IDEA] RESTful service client #3635
Comments
What's new of your proposal compared with the current REST implementation? |
@qiangxue Your implementation is service. This is client. It absolutte different. |
@qiangxue Currently we can create RESTful service with Yii 2 and |
I see. Perhaps it should use a different namespace to avoid confusion? Also, there are many different REST API implementations. How would you design these classes to accommodate the differences? For example, the pagination information may be sent in different ways. How will DataProvider know where to look for this information? |
@qiangxue This is why i post is as just idea to start discussion around it. |
If I whould create an extension to provide some 'fancy' program interface for REST service, I would create an 'Query/ActiveRecord/ActiveQuery' type extension. Like the one for 'ElasticSearch'. Still I am unsure such extension is worth the effots. I have worked with many APIs including ones using REST. But I can not remember any of them following REST standards at full scope. |
I believe similar functionality is implemented in the ActiveResource extension for Yii1 - maybe @Haensel has some learnings he could share... |
@klimov-paul I do not think
Example? |
Well, we can also say there is no need for specific extension for REST client as it not so complicated. Creating full scale Active Record layer will make such extension consitent with other framework parts. Creating a model for the rest data set allows working with via regular Yii forms. Also framework allows cross AR relations, which means we can link REST resource to relational database, which may be useful. |
Really??? Can you show Yii 2 application "Client of RESTful service"??? Not complicated without such layer? Ok, i'm ready to belive with simple example ;-) For now such task (without such components) looks like super complicated.
It theory yes. But trying to implement it show that Yii 2 ActiveRecord/ActiveQuery/Query interfaces absolutte not ready for working with RESTful services with components based on it.
At first look yes. I'm also think so 3 days ago. Can NOT be used at all. To understand why think about header "X-Page-Total-Count" and about headers... What ActiveDataProvider know about headers? Nothing!
Great. Think what you will send to RESTful service when using offset() and limit() methods :-) There is many reasons why you can't look at RESTful services like on SQL/Non-SQL DBs. This need other approach. Yes its API can look like ActiveRecord/ActiveQuery classes API, but can't implement current interfaces or extends current classes. |
My first expirience with REST wa 5 years ago, when Yii did not even exist. I have used pure
What about ElasticSearch then? Its interface follows REST standard, @cebe have composed a fine solution for it with Active Record layer:
Yes, and it should. That is why |
I agree that qualified developer can even develop web app with pure php. But how does qualification related to set of components which just comfortable to use? Seems even qualified developer use frameworks, etc ;-)
I learned @cebe extension before i say you that basing ActiveResource components on existing Yii 2 components/interfaces is impossible. At least without refactoring its architecture. Ok I'll show you simple example from
You see that? What that mean? There will be 2nd query to REST server in addition to main query. But we need one query to get all data we need. And there is A LOT of such nuances. I can list some of them:
For me personally i found another way. Its creating https://github.com/zendframework/ZendService_Twitter And using |
Set milestone to 2.1 for now (it doesn't mean it can't go into 2.0 if there's a pull request). |
Not used it myself (yet) but perhaps Trucker can be used for this or at least provide inspiration - https://github.com/Indatus/trucker |
I think this would be a very useful addition to the framework. More and more of my projects involve grafting in some external functionality or data source via RESTful API. In looking at how to implement this, consider the Httpful curl wrapper from Nate Good https://github.com/nategood/httpful - it can be a example for some of the core functions in implementing a generic REST API accessor. |
This looks great, we started developing an application on Yii, that doesn't use a database at all, and all CRUD operations go through a RESTful API. So, we are wondering now how to design the solution to get a similar functionality provided by ActiveRecord, so that it could be compatible with all Yii forms, widgets, data binding and validations. No more news, ideas, approaches about this? |
+1 |
How is this issue? Some evolution? |
+1 |
1 similar comment
👍 |
+1 any update about this topic? :) |
+1 I am working a lot with multiple Yii2 applications which communicating over REST with each other. Such REST client should be very helpful here. |
Actually i've been tinkering with Guzzle (http://guzzle.readthedocs.org/en/latest/) library and is pretty neat, with all the service descriptions and event system, it really works great, it could be wrapped to add to yii, I though |
what would be the benefit of a wrapper? Why not use it directly? |
Yes, of curse it could be used directly, but I guess it could be better structured to where to put the different things it uses, I mean, for me it was a little of a pain, to give it the propper structure and still is, the clients, descriptions, subscribers, responses, some parsers to implement in some cases, etc, at first glance, you get overwhelmed. Just an idea. |
+1 need to connect restful users with accounts in new system developed on Yii2. |
+1 We need it!!! |
+1 |
+100 |
Same with @quarkmarino vote for Guzzle |
I think it should be an ActiveResource class with interface like in ActiveRecord. |
+1 |
1 similar comment
+1 |
+1 |
See "Tools to use API as ActiveRecord for Yii2" => https://github.com/hiqdev/yii2-hiar |
You mean https://github.com/hiqdev/yii2-hiart? |
@samdark , He's the most ) |
"hiqdev/yii2-hiart" v 0.0.2 (dev) use Guzzle |
+1 |
2 similar comments
+1 |
+1 |
@ApexWire what's the difference from https://github.com/hiqdev/yii2-hiart? |
Default Yii2 Rest creates APIs, which is presented here: In https://github.com/hiqdev/yii2-hiart other APIs, which are not compatible Yii2 Rest and require design improvements. For example:
|
I think it's time to close this issue. There are well implemented clients and clients overall aren't as common in server apps. |
How i see that. Several classes:
and probably:
Configuring:
Example of resource class:
Now we can do:
For data provider there is 2 alternative ideas:
and
Why custom DataProvider? To work with current \yii\rest\ActiveController and other components and play well with headers which containts pagination data, total count, etc.
@qiangxue What you think about it?
The text was updated successfully, but these errors were encountered: