# Following / Followers API

Base URL: `${FORGEJO_URL}/api/v1`

## Current User's Followers

```
GET /user/followers
```

**Parameters:**
| Name | Type | In | Description |
|------|------|------|-------------|
| page | integer | query | Page number (1-based) |
| limit | integer | query | Page size |

```bash
curl -s \
  -H "Authorization: token ${FORGEJO_PAT}" \
  "${FORGEJO_URL}/api/v1/user/followers?page=1&limit=20"
```

**Response:** Array of `User` objects.

---

## Users Current User Follows

```
GET /user/following
```

**Parameters:**
| Name | Type | In | Description |
|------|------|------|-------------|
| page | integer | query | Page number (1-based) |
| limit | integer | query | Page size |

```bash
curl -s \
  -H "Authorization: token ${FORGEJO_PAT}" \
  "${FORGEJO_URL}/api/v1/user/following?page=1&limit=20"
```

---

## Check if Current User Follows a User

```
GET /user/following/{username}
```

Returns `204 No Content` if following, `404` if not.

```bash
curl -s -o /dev/null -w "%{http_code}" \
  -H "Authorization: token ${FORGEJO_PAT}" \
  "${FORGEJO_URL}/api/v1/user/following/{target}"
```

---

## Follow a User

```
PUT /user/following/{username}
```

```bash
curl -s -X PUT \
  -H "Authorization: token ${FORGEJO_PAT}" \
  "${FORGEJO_URL}/api/v1/user/following/{target}"
```

Returns `204 No Content` on success.

---

## Unfollow a User

```
DELETE /user/following/{username}
```

```bash
curl -s -X DELETE \
  -H "Authorization: token ${FORGEJO_PAT}" \
  "${FORGEJO_URL}/api/v1/user/following/{target}"
```

Returns `204 No Content` on success.

---

## Get a User's Followers

```
GET /users/{username}/followers
```

**Parameters:**
| Name | Type | In | Description |
|------|------|------|-------------|
| page | integer | query | Page number (1-based) |
| limit | integer | query | Page size |

```bash
curl -s \
  -H "Authorization: token ${FORGEJO_PAT}" \
  "${FORGEJO_URL}/api/v1/users/{username}/followers?page=1&limit=20"
```

---

## Get Users a User Follows

```
GET /users/{username}/following
```

**Parameters:**
| Name | Type | In | Description |
|------|------|------|-------------|
| page | integer | query | Page number (1-based) |
| limit | integer | query | Page size |

```bash
curl -s \
  -H "Authorization: token ${FORGEJO_PAT}" \
  "${FORGEJO_URL}/api/v1/users/{username}/following?page=1&limit=20"
```

---

## Check if a User Follows Another User

```
GET /users/{username}/following/{target}
```

Returns `204 No Content` if `{username}` follows `{target}`, `404` otherwise.

```bash
curl -s -o /dev/null -w "%{http_code}" \
  -H "Authorization: token ${FORGEJO_PAT}" \
  "${FORGEJO_URL}/api/v1/users/{username}/following/{target}"
```

---

## Example: List all mutual follows

```bash
# Get users I follow
FOLLOWING=$(curl -s \
  -H "Authorization: token ${FORGEJO_PAT}" \
  "${FORGEJO_URL}/api/v1/user/following?limit=50" | jq -r '.[].login')

# Get my followers
FOLLOWERS=$(curl -s \
  -H "Authorization: token ${FORGEJO_PAT}" \
  "${FORGEJO_URL}/api/v1/user/followers?limit=50" | jq -r '.[].login')

# Find mutual follows
comm -12 <(echo "$FOLLOWING" | sort) <(echo "$FOLLOWERS" | sort)
```


---

## List Current User's Teams

```
GET /user/teams
```

Lists all teams the authenticated user belongs to, across all organizations.

**Parameters:**

| Name  | Type    | In    | Description         |
|-------|---------|-------|---------------------|
| page  | integer | query | Page number (1-based) |
| limit | integer | query | Page size             |

```bash
curl -s "${FORGEJO_URL}/api/v1/user/teams?limit=50" \
  -H "Authorization: token ${FORGEJO_PAT}"
```

**Response:** Array of `Team` objects. Each team includes the `organization` field so you can see which org each team belongs to.

```json
[
  {
    "id": 42,
    "name": "Developers",
    "description": "Core development team",
    "organization": {
      "id": 10,
      "name": "{org}",
      "full_name": "My Organization"
    },
    "permission": "write",
    "units": ["repo.code", "repo.issues", "repo.pulls"],
    "includes_all_repositories": false,
    "can_create_org_repo": true
  }
]
```

> **Tip:** This is useful for discovering which teams and organizations the current API token has access to. To list teams for a specific org, use `GET /orgs/{org}/teams` instead.
