API Documentation

1. Overview

This document describes the API interfaces of the Learning Log application, including user management, Topic management, and Entry management.

2. API Basic Information

2.1 Basic URL Structure

http://127.0.0.1:8000/api/

2.2 Authentication

- Uses Session authentication

- After logging in, a Session ID will be returned, which needs to be carried in subsequent requests

2.3 Data Format

- Requests and responses use JSON format

- Please add Content-Type: application/json in the request header

3. Endpoint List

Endpoint Method Function Authentication Required
/api/register/ POST User Registration No
/api/login/ POST User Login No
/api/topics/ GET Get Topic List Yes
/api/topics/ POST Create Topic Yes
/api/topics/{id}/ GET Get Single Topic Yes
/api/topics/{id}/ PUT Update Topic Yes
/api/topics/{id}/ DELETE Delete Topic Yes
/api/entries/ GET Get Entry List Yes
/api/entries/ POST Create Entry Yes
/api/entries/{id}/ GET Get Single Entry Yes
/api/entries/{id}/ PUT Update Entry Yes
/api/entries/{id}/ DELETE Delete Entry Yes

4. Detailed Endpoint Description

4.1 User Registration

URL: /api/register/

Method: POST

Authentication: No

Request Body:

{"username": "string", "password": "string"}

Response Example:

{"id": 1, "username": "testuser"}

4.2 User Login

URL: /api/login/

Method: POST

Authentication: No

Request Body:

{"username": "string", "password": "string"}

Response Example:

{"message": "Login successful"}

5. Usage Examples

5.1 Register New User

curl -X POST http://127.0.0.1:8000/api/register/ -H "Content-Type: application/json" -d '{"username":"testuser","password":"testpassword"}'

5.2 Login and Create Topic

# Login to get Session
curl -X POST http://127.0.0.1:8000/api/login/ -H "Content-Type: application/json" -d '{"username":"testuser","password":"testpassword"}' --cookie-jar cookies.txt

# Create Topic using Session
curl -X POST http://127.0.0.1:8000/api/topics/ -H "Content-Type: application/json" -d '{"text":"Test Topic"}' --cookie cookies.txt

6. Security Notes

  1. Please ensure to use HTTPS protocol in production environment
  2. It is recommended to use Token or JWT authentication instead of Session authentication to improve security
  3. Add appropriate permission control for sensitive operations
  4. Implement API rate limiting to prevent abuse
  5. Regularly update dependency libraries to fix security vulnerabilities