In other words, the Top API SDK only gives the SDK to four languages by default, without My big nodejs, which can be done, thus encapsulating one.
Reference address
Github:https://github.com/xiaoppp/topapi-node
Npm:https://www.npmjs.com/package/topapi-node
Topapi SDK for node. js
======
Using ES6 Promise, all API return promise.
[! [NPM] (Https://nodei.co/npm/topapi-node.png)] (https://nodei.co/npm/topapi-node/)
Platform compatibility
-------
Using Promise, Generator features of ES6
When using node 0.11.x or greater, you must use the--harmony-generators flag or just--harmony to get access to generator S.
When using the node 0.10.x and lower or browsers without generator support, you must use Gnode and/or regenerator.
Io.js is supported out of the box, you can use the CO without flags or polyfills.
Install
-------
```
$ NPM Install Topapi-node
```
Usage
-----
"JS
var Top = require ("Topapi-node");
var top = new Top ({
AppKey: "",
Appsecret: "",
SessionKey: ""
});
var params = {
PAGE_SIZE:200,
Fields: "Num_iid,title,price,pic_url,num,seller_cids,modified,list_time,has_showcase"
}
Top.taobao_items_onsale_get (params). Then (
(data) = {
Console.log (data);
},
(err) = Console.log (err)
)
```
Extend Top Apis
-----
"JS
Since Topapi has huge APIs, and this is only implements some of them, so we have both ways to extend that, both of them were Fine.
Maybe the best-of-the-contribute your code into Lib/apis file. :)
First, you can extend the TOPAPI prototype
Top.prototype.taobao_items_onsale_get = function (params) {
let self = this;
Let method = "Taobao.items.onsale.get";
return new Promise ((resolve, reject) = {
Self.postapi (method, params). Then (
(body) = {resolve (body.items_onsale_get_response);},
(err) = Reject (Err)
);
});
}
Second, Postapi to server
Let method = "Taobao.items.onsale.get";
var params = {
PAGE_SIZE:200,
Fields: "Num_iid,title,price,pic_url,num,seller_cids,modified,list_time,has_showcase"
}
Top.postapi (method, params). Then (
(body) = {
Console.log (body);
},
(err) = Console.log (err)
)
```
Process Control
-----
Suggest to use <a href= "Https://github.com/tj/co" >CO</a> for Process Control
"JS
Co (function* () {
Let param = {
parent_id:0,
Picture_category_name: "Test"
};
Let category = Yield top.taobao_picture_category_get (param);
if (category) {
Category = Yield top.taobao_picture_category_add (param);
}
Return Promise.resolve (category);
}
```
License
-----
(c) Fork Ltd. Licensed under the MIT license.
Using ES6 Features
Promise
Array Function
Generator
Personally think the best use of the Taobao API Nodejs package