|
12 | 12 | - [Code review](#code-review)
|
13 | 13 | - [Styleguide](#styleguide)
|
14 | 14 | - [Design guideline](#design-guideline)
|
| 15 | + - [API v1](#api-v1) |
15 | 16 | - [Developer Certificate of Origin (DCO)](#developer-certificate-of-origin-dco)
|
16 | 17 | - [Release Cycle](#release-cycle)
|
17 | 18 | - [Maintainers](#maintainers)
|
@@ -177,6 +178,43 @@ To maintain understandable code and avoid circular dependencies it is important
|
177 | 178 | - **templates:** Golang templates for generating the html output.
|
178 | 179 | - **vendor:** External code that Gitea depends on.
|
179 | 180 |
|
| 181 | +## API v1 |
| 182 | + |
| 183 | +The API is documented by [swagger](http://try.gitea.io/api/swagger) and is based on [GitHub API v3](https://developer.github.com/v3/). |
| 184 | +Thus, Gitea´s API should use the same endpoints and fields as GitHub´s API as far as possible, unless there are good reasons to deviate. |
| 185 | +If Gitea provides functionality that GitHub does not, a new endpoint can be created. |
| 186 | +If information is provided by Gitea that is not provided by the GitHub API, a new field can be used that doesn't collide with any GitHub fields. |
| 187 | + |
| 188 | +Updating an existing API should not remove existing fields unless there is a really good reason to do so. |
| 189 | +The same applies to status responses. If you notice a problem, feel free to leave a comment in the code for future refactoring to APIv2 (which is currently not planned). |
| 190 | + |
| 191 | +All expected results (errors, success, fail messages) should be documented |
| 192 | +([example](https://github.com/go-gitea/gitea/blob/c620eb5b2d0d874da68ebd734d3864c5224f71f7/routers/api/v1/repo/issue.go#L319-L327)). |
| 193 | + |
| 194 | +All JSON input types must be defined as a struct in `models/structs/` |
| 195 | +([example](https://github.com/go-gitea/gitea/blob/c620eb5b2d0d874da68ebd734d3864c5224f71f7/modules/structs/issue.go#L76-L91)) |
| 196 | +and referenced in |
| 197 | +[routers/api/v1/swagger/options.go](https://github.com/go-gitea/gitea/blob/c620eb5b2d0d874da68ebd734d3864c5224f71f7/routers/api/v1/swagger/options.go). |
| 198 | +They can then be used like the following: |
| 199 | +([example](https://github.com/go-gitea/gitea/blob/c620eb5b2d0d874da68ebd734d3864c5224f71f7/routers/api/v1/repo/issue.go#L318)). |
| 200 | + |
| 201 | +All JSON responses must be defined as a struct in `models/structs/` |
| 202 | +([example](https://github.com/go-gitea/gitea/blob/c620eb5b2d0d874da68ebd734d3864c5224f71f7/modules/structs/issue.go#L36-L68)) |
| 203 | +and referenced in its category in `routers/api/v1/swagger/` |
| 204 | +([example](https://github.com/go-gitea/gitea/blob/c620eb5b2d0d874da68ebd734d3864c5224f71f7/routers/api/v1/swagger/issue.go#L11-L16)) |
| 205 | +They can be used like the following: |
| 206 | +([example](https://github.com/go-gitea/gitea/blob/c620eb5b2d0d874da68ebd734d3864c5224f71f7/routers/api/v1/repo/issue.go#L277-L279)) |
| 207 | + |
| 208 | +In general, HTTP methods are chosen as follows: |
| 209 | + * **GET** endpoints return requested object and status **OK (200)** |
| 210 | + * **DELETE** endpoints return status **No Content (204)** |
| 211 | + * **POST** endpoints return status **Created (201)**, used to **create** new objects (e.g. a User) |
| 212 | + * **PUT** endpoints return status **No Content (204)**, used to **add/assign** existing Obejcts (e.g. User) to something (e.g. Org-Team) |
| 213 | + * **PATCH** endpoints return changed object and status **OK (200)**, used to **edit/change** an existing object |
| 214 | + |
| 215 | + |
| 216 | +An endpoint which changes/edits an object expects all fields to be optional (except ones to identify the object, which are required). |
| 217 | + |
180 | 218 |
|
181 | 219 | ## Developer Certificate of Origin (DCO)
|
182 | 220 |
|
|
0 commit comments