OpenPromptBank is an AI prompt library platform where users can explore, rank, and contribute AI prompts categorized by various topics. This platform features a searchable library, community-driven rankings, prompt performance benchmarks, and user profiles. The backend is powered by Django, Django REST Framework (DRF), and PostgreSQL, with Docker used for containerization.
http://127.0.0.1:8000/api/auth/
POST /register/
Allows new users to register by providing their username, email, and password.
None (public endpoint).
{
"username": "your_username",
"email": "your_email@example.com",
"password": "your_secure_password"
}
- 201 Created (Successful Registration)
{ "message": "User registered successfully" }
- 400 Bad Request (Validation Errors)
{ "username": ["This field is required."], "email": ["Enter a valid email address."] }
POST /login/
Authenticates a user and returns a JSON Web Token (JWT) for session management.
None (public endpoint).
{
"username": "your_username",
"password": "your_secure_password"
}
- 200 OK (Successful Login)
{ "refresh": "your_refresh_token", "access": "your_access_token" }
- 401 Unauthorized (Invalid Credentials)
{ "error": "Invalid credentials" }
POST /token/refresh/
Generates a new access token using a valid refresh token.
None (public endpoint).
{
"refresh": "your_refresh_token"
}
- 200 OK (Token Refreshed)
{ "access": "new_access_token" }
- 401 Unauthorized (Invalid/Expired Refresh Token)
{ "detail": "Token is invalid or expired" }
GET /protected/
Access restricted to authenticated users only. Requires a valid JWT access token in the request header.
{
"Authorization": "Bearer your_access_token"
}
- 200 OK (Authorized)
{ "message": "You are authenticated!" }
- 401 Unauthorized (Invalid or Missing Token)
{ "detail": "Authentication credentials were not provided." }
Status Code | Description |
---|---|
200 | Success |
201 | Resource created |
400 | Bad request (validation error) |
401 | Unauthorized (authentication failed) |
500 | Server error |
- Token Storage: The React frontend should store the
access
andrefresh
tokens securely (e.g.,localStorage
orhttpOnly cookies
). - Authorization Header: Include the
Authorization: Bearer <access_token>
header in requests to protected routes. - Token Refresh Flow:
- Use
/token/refresh/
to renew the access token before it expires. - Redirect to login if the refresh token also expires.
- Use