Backend API service for Echo Trails application. Built with FastAPI and MongoDB.
https://echo-trails-backend.vercel.app
GET /Response (200 OK):
{
"message": "Hello from Echo Trails API",
"status": "ok"
}POST /users/register
Content-Type: application/jsonRequest:
{
"username": "johndoe",
"email": "john@example.com",
"password": "securepassword"
}Response (201 Created):
{
"_id": "65f1a2b3c4d5e6f7g8h9i0j1",
"username": "johndoe",
"email": "john@example.com",
"created_at": "2024-03-26T10:00:00.000Z"
}POST /users/login
Content-Type: application/jsonRequest:
{
"email": "john@example.com",
"password": "securepassword"
}Response (200 OK):
{
"access_token": "eyJhbGciOiJIUzI1NiIs...",
"token_type": "bearer"
}GET /users/identify
Authorization: Bearer <access_token>Response (200 OK):
{
"status": "success",
"token_info": {
"user_id": "65f1a2b3c4d5e6f7g8h9i0j1",
"issued_at": "2024-03-26T10:00:00.000Z",
"expires_at": "2024-03-26T10:30:00.000Z",
"token_valid": true,
"scopes": []
},
"user_data": {
"id": "65f1a2b3c4d5e6f7g8h9i0j1",
"username": "johndoe",
"email": "john@example.com",
"created_at": "2024-03-26T10:00:00.000Z",
"followers": ["65f1a2b3c4d5e6f7g8h9i0j2"],
"following": ["65f1a2b3c4d5e6f7g8h9i0j3"],
"pending_follow_requests": ["65f1a2b3c4d5e6f7g8h9i0j4"]
}
}POST /users/follow/request/{username}
Authorization: Bearer <access_token>Response (200 OK):
{
"message": "Follow request sent to username"
}POST /users/follow/accept/{requester_id}
Authorization: Bearer <access_token>Response (200 OK):
{
"message": "Follow request accepted"
}POST /users/follow/reject/{requester_id}
Authorization: Bearer <access_token>Response (200 OK):
{
"message": "Follow request rejected"
}GET /users/follow/requests/pending
Authorization: Bearer <access_token>Response (200 OK):
[
{
"id": "65f1a2b3c4d5e6f7g8h9i0j1",
"username": "johndoe"
}
]POST /users/unfollow/{username}
Authorization: Bearer <access_token>Response (200 OK):
{
"message": "Successfully unfollowed username"
}POST /followers/remove/{username}
Authorization: Bearer <access_token>Response (200 OK):
{
"message": "Successfully removed username from your followers"
}GET /users/following
Authorization: Bearer <access_token>Response (200 OK):
[
{
"id": "65f1a2b3c4d5e6f7g8h9i0j1",
"username": "johndoe"
},
{
"id": "65f1a2b3c4d5e6f7g8h9i0j2",
"username": "janesmith"
}
]Common Error Responses for Follow Operations:
- 400: Bad Request
{ "detail": "Cannot follow yourself" }{ "detail": "Already following this user" }{ "detail": "Follow request already pending" } - 404: Not Found
{ "detail": "User not found" }{ "detail": "No pending follow request found" }
Additional Error Responses for Unfollow Operations:
{
"detail": "Not following this user"
}{
"detail": "This user is not your follower"
}POST /audio/upload/
Authorization: Bearer <access_token>
Content-Type: multipart/form-dataRequest Form Fields:
file: Audio file (required)title: string (required) - Title of the audio recordinglatitude: float (required)longitude: float (required)range: float (required) - Distance range in meters where audio is discoverablehidden_until: datetime ISO string (required)recipient_usernames: string (required) - Comma-separated list of usernames to share with. Audio will ONLY be accessible to these users.
Response (200 OK):
{
"id": "64f7e123...",
"title": "Morning Birds",
"location": {
"latitude": 11.024196,
"longitude": 77.0037728
},
"range": 100,
"hidden_until": "2025-03-28T11:21:54.630Z",
"shared_with": ["user1", "user2"]
}Additional Error Responses:
{
"detail": "At least one recipient is required"
}{
"detail": "User username not found"
}{
"detail": "You are not following username"
}GET /audio/user/files
Authorization: Bearer <access_token>Response (200 OK):
{
"audio_files": [
{
"_id": "65f1a2b3c4d5e6f7g8h9i0j1",
"user_id": "65f1a2b3c4d5e6f7g8h9i0j1",
"username": "john_doe",
"title": "Morning Birds",
"file_name": "recording.mp3",
"location": {
"type": "Point",
"coordinates": [77.5946, 12.9716]
},
"range": 100.0,
"hidden_until": "2024-03-27T10:00:00.000Z",
"created_at": "2024-03-26T10:00:00.000Z",
"audio_data": 1024
}
]
}GET /audio/files/{audio_id}
Authorization: Bearer <access_token>Response (200 OK):
{
"_id": "65f1a2b3c4d5e6f7g8h9i0j1",
"user_id": "65f1a2b3c4d5e6f7g8h9i0j1",
"title": "Morning Birds",
"file_name": "recording.mp3",
"location": {
"type": "Point",
"coordinates": [77.5946, 12.9716]
},
"range": 100.0,
"hidden_until": "2024-03-27T10:00:00Z",
"created_at": "2024-03-26T10:00:00Z"
}GET /audio/files/{audio_id}/download
Authorization: Bearer <access_token>Response:
- Content-Type: audio/mpeg
- Content-Disposition: attachment; filename="original_filename.mp3"
- Binary audio data stream
GET /audio/nearby?latitude=12.9716&longitude=77.5946
Authorization: Bearer <access_token>Parameters:
latitude: float (required) - Current location latitudelongitude: float (required) - Current location longitude
Response (200 OK):
{
"nearby_files": [
{
"_id": "65f1a2b3c4d5e6f7g8h9i0j1",
"user_id": "65f1a2b3c4d5e6f7g8h9i0j1",
"title": "Morning Birds",
"file_name": "recording.mp3",
"location": {
"latitude": 12.9716,
"longitude": 77.5946
},
"range": 100.0,
"distance": 50.25,
"hidden_until": "2024-03-27T10:00:00Z",
"created_at": "2024-03-26T10:00:00Z"
}
],
"location": {
"latitude": 12.9716,
"longitude": 77.5946
}
}Notes:
- Only returns audio files that belong to the authenticated user
- Files are only returned if they are within the specified range
- Distance is returned in meters and rounded to 2 decimal places
- Only returns files where hidden_until date has passed
- Audio data is excluded from the response for performance
DELETE /audio/files/{audio_id}
Authorization: Bearer <access_token>Response (200 OK):
{
"message": "Audio file deleted successfully"
}Notes:
- Only the owner of the audio file can delete it
- Returns 404 if file not found
- Returns 403 if user is not authorized to delete the file
GET /audio/accessible/
Authorization: Bearer <access_token>Response (200 OK):
[
{
"id": "64f7e123...",
"title": "Morning Birds",
"location": {
"latitude": 11.024196,
"longitude": 77.0037728
},
"range": 100,
"hidden_until": "2025-03-28T11:21:54.630Z",
"shared_with": ["user1", "user2"],
"user_id": "65f1a2b3c4d5e6f7g8h9i0j1"
}
]GET /users/all
Authorization: Bearer <access_token>Returns a list of all registered users with their IDs and usernames.
Response (200 OK):
[
{
"id": "65f1a2b3c4d5e6f7g8h9i0j1",
"username": "john_doe"
},
{
"id": "65f1a2b3c4d5e6f7g8h9i0j2",
"username": "jane_smith"
}
]All endpoints may return the following error responses:
{
"detail": "Error message description"
}Or for 500 errors:
{
"detail": {
"message": "Internal server error description",
"error_type": "ErrorClassName",
"error": "Detailed error message"
}
}Common HTTP Status Codes:
- 400: Bad Request
- 401: Unauthorized
- 403: Forbidden
- 404: Not Found
- 500: Internal Server Error
Protected endpoints require Bearer token authentication:
Authorization: Bearer eyJhbGciOiJIUzI1NiIs...Required environment variables in .env:
JWT_SECRET_KEY=your_secret_key
ALGORITHM=HS256
MONGO_DETAILS=mongodb+srv://username:password@cluster.mongodb.net/
- Clone the repository
- Create virtual environment:
python -m venv venv
- Activate virtual environment:
- Windows:
venv\Scripts\activate - Unix:
source venv/bin/activate
- Windows:
- Install dependencies:
pip install -r requirements.txt
- Create
.envfile with required variables - Start development server:
uvicorn main:app --reload
{
"_id": "65f1a2b3c4d5e6f7g8h9i0j1",
"username": "johndoe",
"email": "john@example.com",
"created_at": "2024-03-26T10:00:00.000Z",
"followers": ["65f1a2b3c4d5e6f7g8h9i0j2"],
"following": ["65f1a2b3c4d5e6f7g8h9i0j3"],
"pending_follow_requests": ["65f1a2b3c4d5e6f7g8h9i0j4"],
"accessible_audio_ids": ["64f7e123..."]
}{
"_id": "64f7e123...",
"user_id": "65f1a2b3c4d5e6f7g8h9i0j1",
"title": "Morning Birds",
"location": {
"type": "Point",
"coordinates": [77.0037728, 11.024196]
},
"range": 100,
"hidden_until": "2025-03-28T11:21:54.630Z",
"created_at": "2024-03-26T10:00:00.000Z",
"file_name": "recording.mp3",
"recipient_ids": ["65f1a2b3c4d5e6f7g8h9i0j2"],
"recipient_usernames": ["user1", "user2"]
}