This document provides a comprehensive guide to the TinyGallery Backend API endpoints.
All API requests should be made to: http://your-domain.com/api/v1
Most endpoints require authentication using a bearer token. Include the token in the Authorization header:
Authorization: Bearer <your_access_token>
POST /user/token
Authenticate a user and receive an access token.
Request Body:
{
"username": "string",
"password": "string"
}
Response:
{
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"token_type": "bearer"
}
Possible Errors:
- 401 Unauthorized: Incorrect username or password
- 422 Unprocessable Entity: Invalid input data
POST /user/register
Register a new user.
Request Body:
{
"user_name": "string",
"password": "string",
"email": "string"
}
Response:
{
"status": "success",
"user_id": "uuid-string"
}
Possible Errors:
- 400 Bad Request: Username already exists
- 422 Unprocessable Entity: Invalid input data
POST /userdata/change-password
Change the password for the authenticated user.
Headers:
- Authorization: Bearer <your_access_token>
Request Body:
{
"previous_password": "string",
"new_password": "string",
"confirm_password": "string"
}
Response:
{
"detail": "Password updated successfully"
}
Possible Errors:
- 400 Bad Request: New password and confirmation do not match
- 401 Unauthorized: Invalid token or previous password incorrect
POST /posts/create
Create a new post.
Headers:
- Authorization: Bearer <your_access_token>
- Content-Type: multipart/form-data
Request Body:
is_nsfw
: "true" or "false" (Form data)uploaded_file
: List of image files (Form data)cover
: Cover image file (optional, Form data)post_title
: Title of the post (Form data)description
: Description of the post (Form data)
Response:
{
"status": "success",
"post_id": "uuid-string"
}
Possible Errors:
- 400 Bad Request: Invalid file type or missing required fields
- 401 Unauthorized: Invalid token
PUT /posts/update/{post_uuid_for_update}
Update an existing post.
Headers:
- Authorization: Bearer <your_access_token>
- Content-Type: multipart/form-data
Path Parameters:
post_uuid_for_update
: UUID of the post to update
Request Body:
- Similar to create post, with additional
supplementary_mode
(Form data)
Response:
{
"status": "success",
"updated_fields": ["title", "description"]
}
Possible Errors:
- 400 Bad Request: Invalid file type or missing required fields
- 401 Unauthorized: Invalid token or user doesn't own the post
- 404 Not Found: Post not found
DELETE /posts/remove/{post_uuid_for_remove}
Delete a post.
Headers:
- Authorization: Bearer <your_access_token>
Path Parameters:
post_uuid_for_remove
: UUID of the post to delete
Response:
{
"status": "success",
"deleted_post_id": "uuid-string"
}
Possible Errors:
- 401 Unauthorized: Invalid token or user doesn't own the post
- 404 Not Found: Post not found
GET /resources/posts/{page}
Get a list of posts.
Query Parameters:
page
: Page number (default: 1)limit
: Number of posts per page (default: 20, max: 100)
Response:
{
"total": 100,
"page": 1,
"limit": 20,
"posts": [
{
"id": 1,
"description": "A beautiful sunset",
"share_num": 5,
"post_uuid": "uuid-string",
"nsfw": false,
"user_name": "john_doe",
"post_title": "Evening Sky",
"dots": 42,
"date": "2023-06-15T18:30:00Z",
"cover_url": "http://example.com/images/cover1.jpg",
"avatar": "http://example.com/avatars/john_doe.jpg"
},
// ... more posts
]
}
Possible Errors:
- 400 Bad Request: Invalid page number
GET /resources/posts/single/{post_uuid}
Get details of a single post.
Path Parameters:
post_uuid
: UUID of the post
Response:
{
"id": 1,
"description": "A beautiful sunset",
"share_num": 5,
"post_uuid": "uuid-string",
"nsfw": false,
"user_name": "john_doe",
"post_title": "Evening Sky",
"dots": 42,
"date": "2023-06-15T18:30:00Z",
"files_url": {
"image_files_url": [
"http://example.com/images/sunset1.jpg",
"http://example.com/images/sunset2.jpg"
],
"original_cover_url": "http://example.com/images/cover_original.jpg",
"compressed_cover_url": "http://example.com/images/cover_compressed.jpg"
}
}
Possible Errors:
- 404 Not Found: Post not found
POST /remark/create/inpost
Create a new comment on a post.
Headers:
- Authorization: Bearer <your_access_token>
Request Body:
{
"post_uuid": "uuid-string",
"content": "This is a great post!"
}
Response:
{
"status": "success",
"comment_id": "uuid-string"
}
Possible Errors:
- 400 Bad Request: Missing required fields
- 401 Unauthorized: Invalid token
- 404 Not Found: Post not found
GET /remark/get/inpost/{post_uuid_for_get_remark}/{page}
Get comments for a post.
Path Parameters:
post_uuid_for_get_remark
: UUID of the postpage
: Page number
Query Parameters:
limit
: Number of comments per page (default: 20, max: 100)
Response:
{
"total": 50,
"page": 1,
"limit": 20,
"comments": [
{
"id": 1,
"post_uuid": "uuid-string",
"user_uuid": "user-uuid-string",
"user_name": "jane_doe",
"remark_uuid": "comment-uuid-string",
"content": "This is a great post!",
"date": "2023-06-15T19:00:00Z",
"avatar": "http://example.com/avatars/jane_doe.jpg"
},
// ... more comments
]
}
Possible Errors:
- 400 Bad Request: Invalid page number
- 404 Not Found: Post not found
GET /likes/get/like_status
Get the like status of a post for the authenticated user.
Headers:
- Authorization: Bearer <your_access_token>
Query Parameters:
post_uuid
: UUID of the post
Response:
{
"id": 1,
"post_uuid": "uuid-string",
"user_name": "john_doe",
"user_uuid": "user-uuid-string",
"liked": true,
"date": "2023-06-15T20:00:00Z"
}
Possible Errors:
- 401 Unauthorized: Invalid token
- 404 Not Found: Post not found or user hasn't interacted with the post
POST /likes/send/like
Like or unlike a post.
Headers:
- Authorization: Bearer <your_access_token>
Query Parameters:
post_uuid
: UUID of the post
Response:
{
"status": "success",
"action": "liked", // or "unliked"
"current_likes": 43
}
Possible Errors:
- 401 Unauthorized: Invalid token
- 404 Not Found: Post not found
GET /resources/avatar/{user_name_for_get_avatar}
Get the avatar URLs for a user.
Path Parameters:
user_name_for_get_avatar
: Username
Response:
{
"status": "success",
"avatar_200px": "http://example.com/avatars/john_doe_200.jpg",
"avatar_40px": "http://example.com/avatars/john_doe_40.jpg",
"full_image": "http://example.com/avatars/john_doe_full.jpg"
}
Possible Errors:
- 404 Not Found: User not found
PUT /userdata/set/avatar
Set a new avatar for the authenticated user.
Headers:
- Authorization: Bearer <your_access_token>
- Content-Type: multipart/form-data
Request Body:
avatar
: Image file (Form data)
Response:
{
"status": "success",
"avatar_url": "http://example.com/avatars/john_doe_new.jpg"
}
Possible Errors:
- 400 Bad Request: Invalid file type
- 401 Unauthorized: Invalid token
The following endpoints are only accessible to admin users. All admin endpoints require the Authorization header with a valid admin token.
GET /admin/users
Query Parameters:
page
: Page number (default: 1)limit
: Users per page (default: 20, max: 100)
Response:
{
"total": 1000,
"page": 1,
"limit": 20,
"users": [
{
"id": 1,
"user_name": "john_doe",
"email": "[email protected]",
"date_joined": "2023-01-01T00:00:00Z",
"last_login": "2023-06-15T21:00:00Z",
"is_active": true
},
// ... more users
]
}
POST /admin/users
Request Body:
{
"user_name": "new_user",
"email": "[email protected]",
"password": "securepassword123"
}
Response:
{
"status": "success",
"user_id": "uuid-string"
}
PUT /admin/users/{user_uuid}
Path Parameters:
user_uuid
: UUID of the user to update
Request Body:
{
"email": "[email protected]",
"is_active": false
}
Response:
{
"status": "success",
"updated_fields": ["email", "is_active"]
}
DELETE /admin/users/{user_uuid}
Path Parameters:
user_uuid
: UUID of the user to delete
Response:
{
"status": "success",
"deleted_user_id": "uuid-string"
}
GET /admin/posts
Similar structure to the non-admin get posts endpoint, but includes all posts regardless of user.
POST /admin/posts
Similar structure to the non-admin create post endpoint, but allows specifying the user.
PUT /admin/posts/{post_uuid}
Similar structure to the non-admin update post endpoint, but can update any post.
DELETE /admin/posts/{post_uuid}
Similar structure to the non-admin delete post endpoint, but can delete any post.
GET /admin/comments
Get all comments across all posts.
POST /admin/comments
Create a comment on behalf of any user.
PUT /admin/comments/{comment_uuid}
Update any comment in the system.
DELETE /admin/comments/{comment_uuid}
Delete any comment in the system.
Note: All admin endpoints may return a 403 Forbidden error if the authenticated user is not an admin.