a RESTful API for a novel application. This backend manages users (including administrators), novel content (books, chapters, and pages), and user interactions like bookmarks and likes. It features JWT-based authentication for both users and admins, supporting standard credentials and Google sign-in.
The Mie Novel-app FastAPI Backend provides the core API infrastructure for the "Mie Novel-app," a platform for reading novels. It offers a comprehensive set of RESTful endpoints to handle user management, admin control, and novel content management (books, chapters, pages). Key features include robust JWT-based authentication for secure access, supporting both traditional login and Google sign-in, along with token refresh capabilities.
- User Management: Sign-up, sign-in, retrieve details, update profiles, and manage password changes.
- Admin Management: Separate sign-up/sign-in, invitation system, details retrieval, and admin-level user management (e.g., updating user status).
- Authentication: Secure access via JWT Bearer tokens with refresh token support.
- Content Management (Admin Privelege): CRUD operations for Books, Chapters, and Pages.
- User Interactions: Endpoints for managing user Bookmarks and Likes on chapters.
- Comments: Users can comment on chapters, and both users and admins can manage comments (delete/update).
- Payment Bundles: Endpoints to create, retrieve, update, and delete payment bundles (admin-only).
- Health Check: A simple endpoint to check API operational status.
The API is structured around different functional areas, accessible via the base path /api/v1.
| Endpoint | Summary | Security | Role |
|---|---|---|---|
/user/sign-up |
Register a new user. | None | User |
/user/sign-in |
Log in a user. | None | User |
/user/refresh |
Get a new access token using a refresh token. | Bearer Token | User |
/user/details |
Retrieve the authenticated user's details. | Bearer Token | User |
/user/initiate/change-password |
Start the password change process. | None | User |
/user/conclude/change-password |
Complete the password change process. | None | User |
/user/update |
Update the authenticated user's profile. | Bearer Token | User |
| Endpoint | Summary | Security | Role |
|---|---|---|---|
/admin/sign-up |
Register a new admin (likely via invite). | None | Admin |
/admin/sign-in |
Log in an admin. | None | Admin |
/admin/invite |
Invite a new admin. | Bearer Token | Admin |
/admin/details |
Get authenticated admin details. | Bearer Token | Admin |
/admin/all/details |
Get all admin details. | Bearer Token | Admin |
/user/all/user-details |
Get data for all users. | Bearer Token | Admin |
/user/{userId}/status/{new_status} |
Update a user's status (active, suspended, inactive). | Bearer Token | Admin |
/admin/dashboardAnalytics |
Retrieve dashboard analytics. | Bearer Token | Admin |
| Endpoint | Summary | Security | Role |
|---|---|---|---|
/book/get |
Get all available books. | Bearer Token | User/Admin |
/book/create |
Create a new book. | Bearer Token | Admin |
/book/delete/{bookId} |
Delete a book. | Bearer Token | Admin |
/chapter/create |
Create a new chapter. | Bearer Token | Admin |
/chapter/user/get/allChapters/{bookId} |
Get all chapters for a book. | Bearer Token | User |
/page/create/{bookId} |
Create a new page. | Bearer Token | Admin |
/page/get/{chapterId} |
Get all pages for a chapter. | Bearer Token | User/Admin |
| Endpoint | Summary | Security | Role |
|---|---|---|---|
/bookmark/create |
Add a new bookmark. | None | User |
/bookmark/get/{userId} |
Get a user's bookmarks. | None | User |
/like/create |
Like a chapter. | Bearer Token | User |
/like/remove/{likeId} |
Unlike a chapter. | Bearer Token | User |
/comment/create |
Post a comment on a chapter. | Bearer Token | User |
/comment/get/{chapterId} |
Get all comments for a chapter. | None | User/Admin |
Authentication is handled via JWT Bearer Tokens.
- Sign In: Send credentials to
/user/sign-inor/admin/sign-in. The response will contain an Access Token and a Refresh Token. - Access Token Usage: Include the Access Token in the
Authorizationheader for all protected endpoints in the formatAuthorization: Bearer <Access Token>. - Token Refresh: When the Access Token expires, use the Refresh Token at
/user/refreshor/admin/refreshto obtain a new Access Token.
(This section assumes a standard FastAPI/Python deployment setup. You'll need to fill in specific environment variables and setup steps for a real deployment.)
- Clone the Repository
- Install Dependencies
pip install -r requirements.txt
- Configure Environment Variables
You will need to set up environment variables for the database connection, JWT secret key, and potentially Google sign-in configuration.
DATABASE_URLJWT_SECRET_KEYALGORITHMACCESS_TOKEN_EXPIRE_MINUTES
- Run the Server
uvicorn main:app --reload
Once the server is running, the OpenAPI interactive documentation (Swagger UI) will typically be available at:
- URL:
/docs(e.g.,http://127.0.0.1:8000/docs)
You can use this interface to explore all endpoints, view required schemas, and test API calls directly.