zh Kooboo Logo Documents

Web API

 

 
Users can create web API methods using k.response.json(obj) instead of k.api. The k.api namespace provides a set of methods to facilitate API creation.
 
It supports the get, put, post, and delete methods and automatically handles parameter binding.
 
For example: 
 
//GET /test?id=23 
k.api.get(function (id) {
    return id;
})
//return '23'
 
Apart from get, the usage of the other three methods (put, post, and delete) is similar.
 
k.api.delete(function () { });
k.api.put(function () { });
k.api.post(function () { }); 
 
Return Object
 
If you return a normal object or text, it will be displayed in the frontend as text. If you need to return an error message, the system has several built-in error types.
 
k.api.get(function(id){  
return k.api.forbidden(); 
});
 
k.api.get(function(id){  
return k.api.httpCode(300); 
});

k.api.get(function(id){  
return k.api.badRequest(); 
});
 
k.api.get(function(id){  
return k.api.unauthorized(); 
});

k.api.get(function(id){  
return k.api.notFound(); 
});