Personally think the best use of the Taobao API Nodejs package

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.