Through the query to understand that the blog Park has developed a blog query related interfaces, the list is as follows:
Uri |
Method |
Description |
48hourstopviewposts/{itemcount} |
GET |
48-hour Reading ranking |
Bloggers/recommend/{pageindex}/{pagesize} |
GET |
Page to get a list of recommended blogs |
Bloggers/recommend/count |
GET |
Get the total number of recommended blogs |
Bloggers/search |
GET |
Search Bloggers by author name |
Post/{postid}/comments/{pageindex}/{pagesize} |
GET |
Get article comments |
Post/body/{postid} |
GET |
Get article content |
Sitehome/paged/{pageindex}/{pagesize} |
GET |
Pagination Get home page article List |
Sitehome/recent/{itemcount} |
GET |
Get home page article List |
Tendaystopdiggposts/{itemcount} |
GET |
Recommended rankings within 10 days |
U/{blogapp}/posts/{pageindex}/{pagesize} |
GET |
Page to get a list of personal blog posts |
But when we open one of these interfaces, we find that the provided interface returns XML-formatted content, so you need to convert the XML to JSON data if you need a format that needs to be forwarded back to the foreground:
Then we step by step, first need node to forward this interface proxy to its own interface, in fact, only need express request middleware can be:
Router.get ('/api/getcnblog ', (req, res) and {let url = ' HTTP://WCF.OPEN.CNBLOGS.COM/BLOG/TENDAYSTOPDIGGPOSTS/6 '; Let data = {} request (URL, (error, response, body) = = { res.send (body)}) })
But this time the interface returns data that is still in XML format. So the next step, we need to transform the XML, through the search to understand that node has XML2JS this plug-in, so just need to be introduced in our node file, and then transform the data. The simple code after the change is as follows:
Const XML2JS = require (' XML2JS '), const parsestring = xml2js.parsestring;router.get ('/api/getcnblog ', (req, res) = = { C0/>let url = ' HTTP://WCF.OPEN.CNBLOGS.COM/BLOG/TENDAYSTOPDIGGPOSTS/6 '; Let data = {} request (URL, (error, response, body) = { parsestring (body, (err, result) = { Res.send ({ c5/>code:200, data:result }) })
As a result, you can see that the data sent back to the background has been converted to JSON format:
Done ~
Use Nodejs to get blog Park blog data and handle forwarding