introduction.mdx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 must be sent via the `Authorization` request header.
  43. ```bash
  44. curl -H "Authorization: token {YOUR_ACCESS_TOKEN}" https://gogs.example.com/api/v1/user/repos
  45. ```
  46. </Tab>
  47. </Tabs>
  48. ## Pagination
  49. API responses that return multiple items are paginated. You can specify further pages with the `?page` query parameter.
  50. ```bash
  51. curl https://gogs.example.com/api/v1/repos/alice/hello/issues?page=1
  52. ```
  53. Page numbering is **1-based**. Omitting the `?page` parameter returns the first page.
  54. ### Link header
  55. Pagination info is included in the [Link header](http://tools.ietf.org/html/rfc5988) of each response. Use this to navigate between pages programmatically.
  56. ```http
  57. Link: <https://gogs.example.com/api/v1/repos/alice/hello/issues?page=3>; rel="next",
  58. <https://gogs.example.com/api/v1/repos/alice/hello/issues?page=50>; rel="last"
  59. ```
  60. The possible `rel` values are:
  61. | Name | Description |
  62. |---|---|
  63. | `next` | The link relation for the immediate next page of results. |
  64. | `last` | The link relation for the last page of results. |
  65. | `first` | The link relation for the first page of results. |
  66. | `prev` | The link relation for the immediate previous page of results. |
  67. <Tip>
  68. Always use the Link header values to navigate between pages rather than constructing URLs manually.
  69. </Tip>
  70. ## SDKs
  71. The following best-effort-maintained SDKs are available:
  72. | Language | Repository |
  73. |---|---|
  74. | Go | [gogs/go-gogs-client](https://github.com/gogs/go-gogs-client) |