I like backbone very much, but I use not REST, but rpc over socket.io, so i need to customize somehow Backbone.sync logic, not to send RESTful requests, but to execute my client rpc library methods.
I found such example of Backbone.sync customization:
http://jsfiddle.net/nikoshr/4ArmM/
But not everything is clear for me. In the end Backbone.sync.call() is executed - what is it?
How does it really work? Does it just perform some GET request here, and i can just omit it (i do not have to make any requests as i am using socket), or it makes something important?
My idea is to take this example and just to insert here some rpc calls. Is it right way?
Rather than start with an arbitrary fiddle, why not take a look at the Backbone source code. It's very easy to read and very well documented. Scroll down to the Backbone.Sync section and you'll find that it isn't very hard to override.
Related
We're looking at moving our Integration Tests for our API to CakePHP's version of PHPUnit. We need to test that the returned values from the API are sane (valid JSON, etc...)
The helper methods on the IntegrationTestCase abstract class look really useful, allowing me to simulate requests by simply calling $this->get('/articles') or similar, but from what I can tell there's no way to actually read the response to one of these requests. Am I missing something?
It seems that without the helper methods provided by IntegrationTestCase it would be much harder to make requests. So what's my best option here?
I just realised that I can do this by simply accessing $this->_response. At first I didn't think I could do this because its visibility is protected, but then I realised that I can access it because my test inherits from IntegrationTestCase.
Me and some friends are currently doing a project where we are designing a webpage, where we do a number of api-calls using ajax.
We are using the Angular-framework, and we are wondering what is the correct architecture on where to put the API-calls. Right now we have them in our controllers, and saving the results as $scope-objects.
We are however wondering if it would actually be better praxis to have the API-calls in the model. We have been googling a lot, and can't seem to find an answer.
Encapsulating API calls in services is a good idea, but don't try to hide the fact that you are making web requests in your code. Have the services/model return descriptive promises and have your controller use the promises and handle errors gracefully. If using REST, you might want to use Angular's built in $resource factory. If the code is easy to unit test, it will be a sign that you're doing a good job. Being able to easily mock the services will make your controllers a lot easier to test.
Pleeeeease help me... :- )
"You are my only hope".
I need to execute an action asynchronously several thousand times. The action is supposed to fetch email content from external API and it is located in the different controller, so I use requestAction to get it. When I get all the results, then these 1000 email contents are sent as 1000 emails during one request, using other API.
Unfortunately, when run sequentially, it takes a lof of time, so I need to run these request asynchronously.
My question is:
Can I execute
$this->requestAction($myUrl)
...parallelly? For example 100 requests at one time? I've seen a bit of asynchronous examples in PHP, but they all used static files and I need to preserve CakePHP structure to be able to use requestAction.
Thanks to all who can help!
EDIT: By the way, when I tried to run requests via fopen($url, 'r'); and then stream get contents the efficiency was worse than worst, but maybe it could be improved. Don't know, but the requestAction seems to be definitely better option (I think).
Is there any reason why you wouldn't use a shell for this?
Please take a look at: CakePHP Shells
"Deferred Execution" is probably what you are after here, basically you want to send one command not have the user waiting around for it? If so then you can use a Message Queue to handle this pretty easily.
We use CakeResque and Redis to send 1000's of emails and perform other API calls
CakeResque - Deferred Processing for CakePHP
There are other message queues that are available but this is really simple to get working and probably wont need much of a change to your code.
In the end, I wasn't able to find a solution that would use requestAction, but I was able to extract the code to a standalone php file, which then is processed using include method.
And the most interesting part, asynchronous requests, was done using great library called cURL-easy and with help of my utility function. You can read about it (how to install and how to use it) here:
Is making asynchronous HTTP requests possible with PHP?
What are the advantages and disadvantages of each? I ask so that i may make better use of the tools. Also, does HttpSocket fallback to using different ways to communicate if, for instance Curl is not available on the server?
If you need to do any kind of a request outside of a GET you will have a hard time using file_get_contents(). HttpSocket won't have any restrictions around HTTP methods or the types of data it can send. file_get_contents() can also be hampered by the allow_fopen_url configuration value being disabled. HttpSocket doesn't have these same issues.
As long as allow_fopen_url is true you could use the stream functions to make file_get_contents() do most anything, but it isn't nearly as simple as using HttpSocket in my opinion.
I'm trying to use an combo item to query a WCF Data Service operation. Data Service wants the operation parameter enclosed in single quotes. Of course Sencha just stuffs the actual string into what is set as "queryParam". Is there an easy way (configure) to get it to quote the parameter, or am I going to have to code the building of the URI?
This sounds like such a stupid simple thing that I almost hate to ask. But, this represents a big disconnect between what WCF DS wants and what Ext produces and is going to cause pervasive problems with strings if I don't have the cleanest way to handle it in place.
When I had to do something similar I wrote a custom proxy for the ext store. The read function is where you have access to the operation's filters which you can turn into a filter string odata understands. Then you have to make the request, format the response, and call the callback.
I don't know of an easier way. There's an official-ish odata proxy for sencha touch here and one for extjs that was posted on the forums here. They might give you some ideas.