index.html.twig 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. {% extends "PackagistWebBundle::layout.html.twig" %}
  2. {% block content %}
  3. <h2 class="title">{{ 'api_doc.title'|trans }}</h2>
  4. <ul class="toc">
  5. <li><a href="#list-packages">{{ 'api_doc.listing_names'|trans }}</a>
  6. <ul>
  7. <li><a href="#list-packages-all">{{ 'api_doc.all_packages'|trans }}</a></li>
  8. <li><a href="#list-packages-by-organization">{{ 'api_doc.by_organization'|trans }}</a></li>
  9. <li><a href="#list-packages-by-type">{{ 'api_doc.by_type'|trans }}</a></li>
  10. </ul>
  11. </li>
  12. <li><a href="#search-packages">{{ 'api_doc.searching'|trans }}</a>
  13. <ul>
  14. <li><a href="#search-packages-by-tag">{{ 'api_doc.by_tag'|trans }}</a></li>
  15. <li><a href="#search-packages-by-name">{{ 'api_doc.by_name'|trans }}</a></li>
  16. <li><a href="#search-packages-by-type">{{ 'api_doc.by_type'|trans }}</a></li>
  17. </ul>
  18. </li>
  19. <li><a href="#get-package-data">{{ 'api_doc.get_package_data'|trans }}</a></li>
  20. </ul>
  21. <section class="col-d-12">
  22. <h3 id="list-packages">{{ 'api_doc.listing_names'|trans }}</h3>
  23. <h4 id="list-packages-all">{{ 'api_doc.all_packages'|trans }}</h4>
  24. <pre>
  25. GET https://{{ packagist_host }}/packages/list.json
  26. <code>
  27. {
  28. "packageNames": [
  29. "[vendor]/[package]",
  30. ...
  31. ]
  32. }
  33. </code></pre>
  34. <p>Working example: <code><a href="https://{{ packagist_host }}/packages/list.json">https://{{ packagist_host }}/packages/list.json</a></code></p>
  35. <h4 id="list-packages-by-organization">{{ 'api_doc.list_by_organization'|trans }}</h4>
  36. <pre>
  37. GET https://{{ packagist_host }}/packages/list.json?vendor=[vendor]
  38. <code>
  39. {
  40. "packageNames": [
  41. "[vendor]/[package]",
  42. ...
  43. ]
  44. }
  45. </code></pre>
  46. <p>Working example: <code><a href="https://{{ packagist_host }}/packages/list.json?vendor=composer">https://{{ packagist_host }}/packages/list.json?vendor=composer</a></code></p>
  47. <h4 id="list-packages-by-type">{{ 'api_doc.list_by_type'|trans }}</h4>
  48. <pre>
  49. GET https://{{ packagist_host }}/packages/list.json?type=[type]
  50. <code>
  51. {
  52. "packageNames": [
  53. "[vendor]/[package]",
  54. ...
  55. ]
  56. }
  57. </code></pre>
  58. <p>Working example: <code><a href="https://{{ packagist_host }}/packages/list.json?type=composer-plugin">https://{{ packagist_host }}/packages/list.json?type=composer-plugin</a></code></p>
  59. </section>
  60. <section class="col-d-12">
  61. <h3 id="search-packages">{{ 'api_doc.searching'|trans }}</h3>
  62. <p>Search results are paginated and you can change the pagination step by using the per_page parameter. For example <code>https://{{ packagist_host }}/search.json?q=[query]&amp;per_page=5</code></p>
  63. <h4 id="search-packages-by-name">{{ 'api_doc.search_by_name'|trans }}</h4>
  64. <pre>
  65. GET https://{{ packagist_host }}/search.json?q=[query]
  66. <code>
  67. {
  68. "results" : [
  69. {
  70. "name": "[vendor]/[package]",
  71. "description": "[description]",
  72. "url": "https://{{ packagist_host }}/packages/[vendor]/[package]",
  73. "repository": [repository url],
  74. "downloads": [number of downloads],
  75. "favers": [number of favers]
  76. },
  77. ...
  78. ],
  79. "total": [number of results],
  80. "next": "https://{{ packagist_host }}/search.json?q=[query]&amp;page=[next page number]"
  81. }
  82. </code></pre>
  83. <p>Working example: <code><a href="https://{{ packagist_host }}/search.json?q=monolog">https://{{ packagist_host }}/search.json?q=monolog</a></code></p>
  84. <h4 id="search-packages-by-tag">{{ 'api_doc.search_by_tag'|trans }}</h4>
  85. <pre>
  86. GET https://{{ packagist_host }}/search.json?tags=[tag]
  87. <code>
  88. {
  89. "results": [
  90. {
  91. "name": "[vendor]/[package]",
  92. "description": "[description]",
  93. "url": "https://{{ packagist_host }}/packages/[vendor]/[package]",
  94. "repository": "[repository url]",
  95. "downloads": [number of downloads],
  96. "favers": [number of favers]
  97. }
  98. ...
  99. ],
  100. "total": [numbers of results]
  101. }
  102. </code></pre>
  103. <p>Working example: <code><a href="https://{{ packagist_host }}/search.json?q=monolog&amp;tags=psr-3">https://{{ packagist_host }}/search.json?q=monolog&amp;tags=psr-3</a></code></p>
  104. <h4 id="search-packages-by-type">{{ 'api_doc.search_by_type'|trans }}</h4>
  105. <pre>
  106. GET https://{{ packagist_host }}/search.json?q=[query]&amp;type=symfony-bundle
  107. <code>
  108. {
  109. "results" : [
  110. {
  111. "name": "[vendor]/[package]",
  112. "description": "[description]",
  113. "url": "https://{{ packagist_host }}/packages/[vendor]/[package]",
  114. "repository": [repository url],
  115. "downloads": [number of downloads],
  116. "favers": [number of favers]
  117. },
  118. ...
  119. ],
  120. "total": [number of results],
  121. "next": "https://{{ packagist_host }}/search.json?q=[query]&amp;page=[next page number]"
  122. }
  123. </code></pre>
  124. <p>Working example: <code><a href="https://{{ packagist_host }}/search.json?q=monolog&amp;type=symfony-bundle">https://{{ packagist_host }}/search.json?q=monolog&amp;type=symfony-bundle</a></code></p>
  125. </section>
  126. <section class="col-d-12">
  127. <h3 id="get-package-data">{{ 'api_doc.get_package_data'|trans }}</h3>
  128. <h4 id="get-package-by-name">Using the Composer metadata</h4>
  129. <p>This is the preferred way to access the data as it is always up to date, and dumped to static files so it is very efficient on our end.</p>
  130. <p>You can also send If-Modified-Since headers to limit your bandwidth usage and cache the files on your end with the proper filemtime set according to our Last-Modified header.</p>
  131. <p>There are a few gotchas though with using this method:
  132. <ul>
  133. <li>It only provides you with the package metadata but not information about the maintainers, download stats or github info.</li>
  134. <li>It contains providers information which must be ignored but can appear confusing at first. This will disappear in the future though.</li>
  135. </ul>
  136. </p>
  137. <pre>
  138. GET https://{{ packagist_host }}/p/[vendor]/[package].json
  139. <code>
  140. {
  141. "packages": {
  142. "[vendor]/[package]": {
  143. "[version1]": {
  144. "name": "[vendor]/[package],
  145. "description": [description],
  146. // ...
  147. },
  148. "[version2]": {
  149. // ...
  150. }
  151. // ...
  152. }
  153. }
  154. }
  155. </code></pre>
  156. <p>Working example: <code><a href="https://{{ packagist_host }}/p/monolog/monolog.json">https://{{ packagist_host }}/p/monolog/monolog.json</a></code></p>
  157. <h4 id="get-package-by-name">Using the API</h4>
  158. <p>The JSON API for packages gives you all the infos we have including downloads, dependents count, github info, etc. However it is generated dynamically so for performance reason we cache the responses for twelve hours. As such if the static file endpoint described above is enough please use it instead.</p>
  159. <pre>
  160. GET https://{{ packagist_host }}/packages/[vendor]/[package].json
  161. <code>
  162. {
  163. "package": {
  164. "name": "[vendor]/[package],
  165. "description": [description],
  166. "time": [time of the last release],
  167. "maintainers": [list of maintainers],
  168. "versions": [list of versions and their dependencies, the same data of <a href="https://getcomposer.org/doc/01-basic-usage.md#package-versions">composer.json</a>]
  169. "type": [package type],
  170. "repository": [repository url],
  171. "downloads": {
  172. "total": [numbers of download],
  173. "monthly": [numbers of download per month],
  174. "daily": [numbers of download per day]
  175. },
  176. "favers": [number of favers]
  177. }
  178. }
  179. </code></pre>
  180. <p>Working example: <code><a href="https://{{ packagist_host }}/packages/monolog/monolog.json">https://{{ packagist_host }}/packages/monolog/monolog.json</a></code></p>
  181. </section>
  182. {% endblock %}