BackendService.js
Generate multiple ajaxs function with name!!
Initialize
var routes = "name":"users" "method":"GET" "path":"/users" "name":"user" "method":"GET" "path":"/users/:id" "name":"post" "method":"GET" "path":"/posts/:slug" MyApi
Ajax functions generated
Backend service generate function using your path, method and name defined in the routes.json
MyApi //GET /usersMyApi //GET /users/1MyApi //GET /users?location=madridMyApi //GET /post/post-title
Backendservice use superagent.js The generate function i'ts the same with this
Path functions generated
BackendService generate path functions like this
"/users/" == MyApi"/users/3" == MyApi"/post/post-title" == MyApi
Mock in your Unit test
Use the method responseWith to override the ajax function and response immediately
You don't need to change your production code, BackendService call the same callbackSucess but call immediately and the response it's a mock.
Default functions
_get, _post, _delete, _put
MyApi //GET /users?location=madrid
Unauthorized function
BackendService recive a function and called when the response status it's 401
MyApi
Arguments Recive
- MyApi.users( query_data, callbackSucess, callBackError )
- MyApi.create_users( send_data, callbackSuccess, callBackError ) Post|PUT
Arguments contain
- callBackSuccess( response.body, response.status, response )