I think we should write a apiRequest class to pass all requests to the server through, this would give us some abstraction from the endpoints and the ugly CPURLConnection API.
On another project I work on, I use a closure functions to handle the callbacks, as I find having to send a request in one method, then pick it up in another method to continue the process is a bit clunky. This way we would be able to do the following:
var options = [[CPDictionary alloc] initWithValues:["root", "root"] forKeys:["username", "password"]];
[[SJAPIRequest sendRequestToConnectWithOptions: options callback: function( jsonData ) {
//continue doing whatever, you have access to local variables etc etc
}];
Other methods would be sendRequestToQueryWithOptions:, sendRequestToDatabasesWithOptions: etc (for all endpoints).
This would also reduce the code needed, the same with the current way of doing things:
I think we should write a apiRequest class to pass all requests to the server through, this would give us some abstraction from the endpoints and the ugly CPURLConnection API.
On another project I work on, I use a closure functions to handle the callbacks, as I find having to send a request in one method, then pick it up in another method to continue the process is a bit clunky. This way we would be able to do the following:
Other methods would be
sendRequestToQueryWithOptions:
,sendRequestToDatabasesWithOptions:
etc (for all endpoints).This would also reduce the code needed, the same with the current way of doing things:
This would also make it easier to support different server-sides in the future as we would not be tied to the end url scheme.
What do you think about this?