Summery
In the broadest of terms, an API (Application Programming Interface) is a defined way for one piece of software to interact with another.
For example, Gitea provides an API that lets you list repositories, retrieve issues, create users, or push certain changes programmatically, without manually clicking through its web interface.
A typical web API interaction:
- Your client sends an HTTP request.
- The server processes it.
- The server returns a response, often containing data.
Types of API interfaces
REST
Representational State Transfer (REST) is an architectural style commonly used for web APIs.
REST organizes functionality around resources, such as users, repositories, files, or issues. URLs identify resources, while HTTP methods describe what the client wants to do. It usually uses JSON as it’s data format.
Example:
GET /api/users/alice - Retrieve Alice’s information
GET /api/users/alice/repos - List Alice’s repositories
POST /api/repos - Create a repository
PATCH /api/repos/project - Modify a repository
DELETE /api/repos/project - Delete a repository
Gitea also uses RESTful API.
SOAP
Simple Object Access Protocol (SOAP) is a protocol for exchanging structured messages, usually encoded in XML. It often uses WSDL (Web Services Description Language) to describe operations and message formats.
Unlike REST’s resource-oriented approach, SOAP commonly exposes operations described by a service contract (like GetUser or DeleteUser).
Example:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetUser>
<UserId>123</UserId>
</GetUser>
</soap:Body>
</soap:Envelope>GraphQL
GraphQL is a query language and runtime that lets a client request exactly the fields they need. The client specifies which fields they and the server returns those fields in a matching structure.
Instead of calling separate endpoints for users and repositories, a GraphQL API often exposes a single endpoint, such as /graphql. It commonly uses JSON as it’s data format.
Example:
query {
user(username: "alice") {
username
repositories {
name
}
}
}References
You can read the Data formats note to refresh your knowledge on them.