1
0

introduction.mdx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. ---
  2. title: "Introduction"
  3. sidebarTitle: "Introduction"
  4. description: "Overview of the Gogs API including authentication, pagination, and schema"
  5. ---
  6. The Gogs API provides a RESTful interface for interacting with your Gogs instance programmatically. It aims to follow a format similar to the [GitHub REST API v3](https://developer.github.com/v3/).
  7. <Info>
  8. The API is bundled with every Gogs installation. No additional setup is required.
  9. </Info>
  10. <Warning>
  11. The API is still in its early stages. Content and endpoints are subject to change.
  12. </Warning>
  13. ## Current version
  14. All Gogs APIs are under **v1** using the request path prefix `/api/v1`.
  15. ```
  16. https://gogs.example.com/api/v1
  17. ```
  18. ## Schema
  19. All data is sent and received as **JSON** unless specified otherwise.
  20. ```http
  21. HTTP/2 200
  22. Content-Type: application/json; charset=UTF-8
  23. ```
  24. All timestamps are returned in **RFC 3339** format:
  25. ```
  26. YYYY-MM-DDTHH:MM:SSZ
  27. 2006-01-02T15:04:05Z07:00
  28. ```
  29. ## Authentication
  30. There are two ways to authenticate through the Gogs API. Requests that require authentication will return `404 Not Found` instead of `403 Forbidden` in some places. This is to prevent the accidental leakage of private resources to unauthorized users.
  31. <Tabs>
  32. <Tab title="Basic authentication">
  33. Basic authentication is used to obtain access tokens. Supply your username (you will be prompted for your password):
  34. ```bash
  35. curl -u "alice" https://gogs.example.com/api/v1/users/alice/tokens
  36. ```
  37. <Warning>
  38. Basic authentication should only be used to generate access tokens. Do not use it for regular API requests.
  39. </Warning>
  40. </Tab>
  41. <Tab title="Access token">
  42. Personal access tokens are the recommended way to authenticate. They can be sent via a request **header** or a **URL query parameter**.
  43. **Using a header:**
  44. ```bash
  45. curl -H "Authorization: token {YOUR_ACCESS_TOKEN}" https://gogs.example.com/api/v1/user/repos
  46. ```
  47. **Using a query parameter:**
  48. ```bash
  49. curl https://gogs.example.com/api/v1/user/repos?token={YOUR_ACCESS_TOKEN}
  50. ```
  51. <Tip>
  52. Using the `Authorization` header is preferred over the query parameter, as URLs may be logged by proxies and servers.
  53. </Tip>
  54. </Tab>
  55. </Tabs>
  56. ## Pagination
  57. API responses that return multiple items are paginated. You can specify further pages with the `?page` query parameter.
  58. ```bash
  59. curl https://gogs.example.com/api/v1/repos/alice/hello/issues?page=1
  60. ```
  61. Page numbering is **1-based**. Omitting the `?page` parameter returns the first page.
  62. ### Link header
  63. Pagination info is included in the [Link header](http://tools.ietf.org/html/rfc5988) of each response. Use this to navigate between pages programmatically.
  64. ```http
  65. Link: <https://gogs.example.com/api/v1/repos/alice/hello/issues?page=3>; rel="next",
  66. <https://gogs.example.com/api/v1/repos/alice/hello/issues?page=50>; rel="last"
  67. ```
  68. The possible `rel` values are:
  69. | Name | Description |
  70. |---|---|
  71. | `next` | The link relation for the immediate next page of results. |
  72. | `last` | The link relation for the last page of results. |
  73. | `first` | The link relation for the first page of results. |
  74. | `prev` | The link relation for the immediate previous page of results. |
  75. <Tip>
  76. Always use the Link header values to navigate between pages rather than constructing URLs manually.
  77. </Tip>
  78. ## SDKs
  79. The following best-effort-maintained SDKs are available:
  80. | Language | Repository |
  81. |---|---|
  82. | Go | [gogs/go-gogs-client](https://github.com/gogs/go-gogs-client) |