Skip to content

Latest commit

 

History

History
323 lines (228 loc) · 4.06 KB

File metadata and controls

323 lines (228 loc) · 4.06 KB

WebRAG Assistant – Backend API Documentation

Base URL:

http://127.0.0.1:8000/api/

1️⃣ DOCUMENT ENDPOINTS

Upload Document

Endpoint

POST /api/documents/

Content-Type

multipart/form-data

Request Body

Key Type Required
file File Yes

Success Response

{
  "message": "Document uploaded successfully",
  "document_id": 1,
  "filename": "resume.pdf",
  "chunks_created": 18
}

Get All Documents

Endpoint

GET /api/documents/

Response

[
  {
    "id": 1,
    "filename": "resume.pdf",
    "uploaded_at": "2026-02-10T12:30:00Z"
  }
]

Get Single Document

Endpoint

GET /api/documents/<id>/

Response

{
  "id": 1,
  "filename": "resume.pdf",
  "uploaded_at": "2026-02-10T12:30:00Z",
  "chunks_count": 18
}

Delete Document

Endpoint

DELETE /api/documents/<id>/

Response

{
  "message": "Document deleted successfully"
}

2️⃣ CHAT (RAG) ENDPOINT

Ask Question

Endpoint

POST /api/chat/

⚠️ Important: Must include trailing slash.

Content-Type

application/json

Request Body

{
  "question": "What skills are mentioned in the document?"
}

Optional (if filtering per document):

{
  "question": "What skills are mentioned?",
  "document_id": 1
}

Backend Processing Flow

  1. Receive question
  2. Generate embedding
  3. Retrieve top matching chunks from vector DB
  4. Send chunks + question to LLM
  5. Generate answer
  6. Return answer + sources

Success Response

{
  "answer": "The document mentions Python, Django, React, and REST APIs.",
  "sources": [
    {
      "document_id": 1,
      "chunk_id": 4,
      "content_preview": "Experienced in Python and Django framework..."
    }
  ]
}

3️⃣ AUTHENTICATION ENDPOINTS

Register

Endpoint

POST /api/auth/register/

Request Body

{
  "email": "user@example.com",
  "password": "password123"
}

Response

{
  "message": "User registered successfully"
}

Login

Endpoint

POST /api/auth/login/

Request Body

{
  "email": "user@example.com",
  "password": "password123"
}

Response (JWT Example)

{
  "access": "ACCESS_TOKEN",
  "refresh": "REFRESH_TOKEN"
}

Get Current User

Endpoint

GET /api/auth/me/

Headers

Authorization: Bearer ACCESS_TOKEN

Response

{
  "id": 1,
  "email": "user@example.com"
}

4️⃣ URL STRUCTURE EXAMPLE

backend/urls.py

from django.urls import path, include

urlpatterns = [
    path("api/", include("documents.urls")),
    path("api/", include("chat.urls")),
    path("api/", include("accounts.urls")),
]

documents/urls.py

from django.urls import path
from .views import DocumentListCreateView, DocumentDetailView

urlpatterns = [
    path("documents/", DocumentListCreateView.as_view()),
    path("documents/<int:pk>/", DocumentDetailView.as_view()),
]

chat/urls.py

from django.urls import path
from .views import ChatAPIView

urlpatterns = [
    path("chat/", ChatAPIView.as_view()),
]

5️⃣ FRONTEND INTEGRATION SUMMARY

Feature Endpoint Method
Upload Document /api/documents/ POST
List Documents /api/documents/ GET
Get One /api/documents// GET
Delete /api/documents// DELETE
Ask Question /api/chat/ POST
Register /api/auth/register/ POST
Login /api/auth/login/ POST
Current User /api/auth/me/ GET

6️⃣ Backend Requirements Checklist

  • MEDIA_ROOT configured
  • CORS enabled
  • Trailing slash used correctly
  • Vector database persistence enabled
  • LLM API key configured
  • Chunking and embedding working

End of API Backend Documentation.