Skip to content

[Docs] Add guide on howto develop API #9587

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Jan 4, 2020
19 changes: 18 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ the same change, be it a bugfix or a feature addition.

The `vendor/` update needs to be justified as part of the PR description,
and must be verified by the reviewers and/or merger to always reference
an existing upstream commit.
an existsing upstream commit.

You can find more information on how to get started with it on the [Modules Uncyclo](https://github.com/golang/go/wiki/Modules).

Expand Down Expand Up @@ -177,6 +177,23 @@ To maintain understandable code and avoid circular dependencies it is important
- **templates:** Golang templates for generating the html output.
- **vendor:** External code that Gitea depends on.

## API v1

The API is documented by [swagger](http://gitea.com/api/swagger) and is based on [GitHub API v3](https://developer.github.com/v3/).
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. If GitHub doesn't provide...

All expected results (errors, success, fail messages) should be documented ([example](https://github.com/go-gitea/gitea/blob/master/routers/api/v1/repo/issue.go#L319-L327)).

All JSON input types must be defined as struct in `models/structs/` ([example](https://github.com/go-gitea/gitea/blob/master/modules/structs/issue.go#L76-L91)) and referenced in [routers/api/v1/swagger/options.go](https://github.com/go-gitea/gitea/blob/master/routers/api/v1/swagger/options.go), they can be used then as following: ([example](https://github.com/go-gitea/gitea/blob/master/routers/api/v1/repo/issue.go#L318)).

All JSON responses must be defined as struct in `models/structs/` ([example](https://github.com/go-gitea/gitea/blob/master/modules/structs/issue.go#L36-L68)) and referenced in its category in `routers/api/v1/swagger/` ([example](https://github.com/go-gitea/gitea/blob/master/routers/api/v1/swagger/issue.go#L11-L16)), they can be used as following: ([example](https://github.com/go-gitea/gitea/blob/master/routers/api/v1/repo/issue.go#L277-L279))

* GET endpoints return status `OK (200)`,
* POST endpoints return status `Created (201)` and
* DELETE endpoints return status `No Content (204)`

An endpoint which changes/edits a object expects all fields to be optional (except ones to identify the object, which is required).


## Developer Certificate of Origin (DCO)

Expand Down