This document provides a comprehensive guide to the LeoConnect Backend API, built with Cloudflare Workers and Firestore.
The base URL depends on your Cloudflare Workers deployment. Locally, it is typically:
http://localhost:8787
Protected endpoints require a valid Firebase ID Token passed in the Authorization header.
Header Format:
Authorization: Bearer <FIREBASE_ID_TOKEN>
Checks if the backend is running.
- URL:
/ - Method:
GET - Auth: Public
- Response:
{ "message": "LeoConnect Backend is running!" }
Authenticates a user with a Google/Firebase ID token and returns the user profile.
- URL:
/auth/google - Method:
POST - Auth: Bearer Token required
- Response:
{ "uid": "user123", "email": "user@example.com", "displayName": "John Doe", "photoURL": "https://...", "leoId": "LEO123", "isWebmaster": false, "assignedClubId": "club456" }
Fetches the latest posts for the home feed.
- URL:
/feed - Method:
GET - Auth: Required
- Query Params:
limit(optional): Number of posts to return.
- Response:
{ "posts": [ { "postId": "post123", "clubId": "club456", "authorName": "John Doe", "authorLogo": "https://...", "content": "Hello world", "imageUrl": "https://...", "likesCount": 42, "isLikedByUser": false, "timestamp": "2023-10-27T10:00:00Z" } ] }
Creates a new post.
- URL:
/posts - Method:
POST - Auth: Required
- Body:
{ "content": "Hello, LeoConnect!", "imageBytes": "base64_encoded_image_string", // Optional "clubId": "club123" // Optional } - Response:
{ "postId": "new_post_id", "clubId": "club123", "authorName": "John Doe", "authorLogo": "https://...", "content": "Hello, LeoConnect!", "imageUrl": "https://...", "likesCount": 0, "isLikedByUser": false }
Likes a specific post.
- URL:
/posts/:id/like - Method:
POST - Auth: Required
- URL Params:
id: The ID of the post to like.
- Response:
{ "message": "Liked post <id>", "likesCount": 1, "isLikedByUser": true }
Retrieves a list of available districts.
- URL:
/districts - Method:
GET - Auth: Public
- Response:
[ "District 306 A1", "District 306 A2", "District 306 B1" ]
Retrieves a list of clubs, optionally filtered by district.
- URL:
/clubs - Method:
GET - Auth: Public
- Query Params:
district(optional): Filter clubs by this district name.
- Response:
[ { "clubId": "club123", "name": "Leo Club of Colombo", "district": "District 306 A1", "description": "We serve the community...", "president": "John Doe" } ]
uid: Firebase UIDemail: User emaildisplayName: User display namephotoURL: Profile picture URLleoId: Leo Club ID (optional)isWebmaster: Boolean indicating admin statusassignedClubId: Club ID the user belongs to
postId: Unique IDclubId: ID of the clubauthorName: Name of the authorauthorLogo: URL of author's logocontent: Text contentimageUrl: URL of the post imagelikesCount: Number of likesisLikedByUser: Booleantimestamp: ISO timestamp
clubId: Unique IDname: Club namedistrict: District namedescription: Club descriptionpresident: President's name