2017-08-26 76 views
0

我正在寻找一种方法来查询npm REST API以返回相关结果。我想将搜索集成到我的应用程序中。如何查询NPM REST API搜索以获得相关结果?

F.e.如果我查询故宫的“引导”我收到了一堆的结果,但不是 Twitter的引导包的第一页上:

请求

curl https://npmsearch.com/query?q=bootstrap&fields=name,description,rating,version

结果

{"results":[{"name":["apta-bootstrap"],"version":["1.0.0"],"description":["apta bootstrap assets"]},{"name":["ender-bootstrap"],"version":["2.2.1"],"description":["Ender version of Twitter's Bootstrap JS (all plugins)"]},{"name":["bootstrap-extends"],"version":["1.0.1"],"description":["Useful extensions for Bootstrap 3"]},{"name":["bootstrap-submenu-hover"],"version":["2.0.8"],"description":["Bootstrap Sub-Menus"]},{"name":["bootstrap-submenu"],"version":["2.0.4"],"description":["Bootstrap Sub-Menus"]},{"name":["bootstrap-toggle-react"],"version":["0.1.6"],"description":["Bootstrap Toggle is a react component providing a toggle, based on www.bootstraptoggle.com"]},{"name":["bootstrap-layout-scrollable"],"version":["1.1.0"],"description":["Bootstrap Layout integration with Simplebar.js"]},{"name":["mithril-admin-bootstrap"],"version":["0.0.2"],"description":["Twitter Bootstrap plugin for mithril-admin"]},{"name":["bootstrap-checkbox"],"version":["1.4.0"],"description":["A checkbox component based on Bootstrap framework"]},{"name":["npmdoc-bootstrap-notify"],"version":["0.0.2"],"description":["#### api documentation for [bootstrap-notify (v3.1.3)](http://bootstrap-notify.remabledesigns.com/) [![npm package](https://img.shields.io/npm/v/npmdoc-bootstrap-notify.svg?style=flat-square)](https://www.npmjs.org/package/npmdoc-bootstrap-notify) [![tr"]}],"total":13546,"from":0}

我怎么可以即兴e NPM搜索的实用性?

yarnpkg.com已经做了很好的工作提供了一个很酷的搜索,但是搜索似乎并不意在被公开访问,即 https://yarnpkg.com/en/packages?q=bootstrap&p=1

你有什么建议吗?

谢谢。

+0

要查询npm包信息,您可以使用npmjs.com的搜索URL。对于Bootstrap,它是:https://www.npmjs.com/-/search?text=bootstrap twitter Bootstrap将是最重要的结果。 – shaochuancs

+0

谢谢。那就是我需要的。 –

+0

欢迎。这些信息已作为答案发布,以便其他访问此问题的人可以快速获得答案。 – shaochuancs

回答

0

要查询NPM包的信息,npmjs.com的搜索URL,可以用:

http://npmjs.com/-/search?text=<search keyword> 

自举,它是:

http://npmjs.com/-/search?text=bootstrap 

的Twitter的引导将是顶级的结果。