first comm

This commit is contained in:
dela
2026-02-11 15:14:20 +08:00
commit 604f323c34
30 changed files with 5475 additions and 0 deletions

510
postman_collection.json Normal file
View File

@@ -0,0 +1,510 @@
{
"info": {
"_postman_id": "blog-backend-collection",
"name": "Rust Blog Backend API",
"description": "API collection for testing the Rust Blog Backend",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"variable": [
{
"key": "base_url",
"value": "http://127.0.0.1:8080",
"type": "string"
},
{
"key": "token",
"value": "",
"type": "string"
},
{
"key": "post_id",
"value": "",
"type": "string"
}
],
"item": [
{
"name": "Auth",
"item": [
{
"name": "Register",
"event": [
{
"listen": "test",
"script": {
"exec": [
"if (pm.response.code === 201) {",
" var jsonData = pm.response.json();",
" pm.collectionVariables.set('token', jsonData.token);",
" console.log('Token saved:', jsonData.token);",
"}"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"email\": \"test@example.com\",\n \"password\": \"password123\"\n}"
},
"url": {
"raw": "{{base_url}}/api/auth/register",
"host": ["{{base_url}}"],
"path": ["api", "auth", "register"]
},
"description": "Register a new user. Saves the JWT token automatically."
},
"response": []
},
{
"name": "Login",
"event": [
{
"listen": "test",
"script": {
"exec": [
"if (pm.response.code === 200) {",
" var jsonData = pm.response.json();",
" pm.collectionVariables.set('token', jsonData.token);",
" console.log('Token saved:', jsonData.token);",
"}"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"email\": \"test@example.com\",\n \"password\": \"password123\"\n}"
},
"url": {
"raw": "{{base_url}}/api/auth/login",
"host": ["{{base_url}}"],
"path": ["api", "auth", "login"]
},
"description": "Login with existing credentials. Saves the JWT token automatically."
},
"response": []
}
],
"description": "Authentication endpoints"
},
{
"name": "Posts",
"item": [
{
"name": "Create Post",
"event": [
{
"listen": "test",
"script": {
"exec": [
"if (pm.response.code === 201) {",
" var jsonData = pm.response.json();",
" pm.collectionVariables.set('post_id', jsonData.id);",
" console.log('Post ID saved:', jsonData.id);",
"}"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Authorization",
"value": "Bearer {{token}}"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"title\": \"My First Blog Post\",\n \"content\": \"This is the content of my first blog post. It contains some interesting text about Rust programming.\",\n \"published\": true\n}"
},
"url": {
"raw": "{{base_url}}/api/posts",
"host": ["{{base_url}}"],
"path": ["api", "posts"]
},
"description": "Create a new blog post. Requires authentication."
},
"response": []
},
{
"name": "Create Draft Post",
"event": [
{
"listen": "test",
"script": {
"exec": [
"if (pm.response.code === 201) {",
" var jsonData = pm.response.json();",
" console.log('Draft Post ID:', jsonData.id);",
"}"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Authorization",
"value": "Bearer {{token}}"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"title\": \"Draft Post - Work in Progress\",\n \"content\": \"This is a draft post that is not yet published.\",\n \"published\": false\n}"
},
"url": {
"raw": "{{base_url}}/api/posts",
"host": ["{{base_url}}"],
"path": ["api", "posts"]
},
"description": "Create a draft post (not published). Requires authentication."
},
"response": []
},
{
"name": "List Posts",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "{{base_url}}/api/posts?page=1&limit=10",
"host": ["{{base_url}}"],
"path": ["api", "posts"],
"query": [
{
"key": "page",
"value": "1",
"description": "Page number (default: 1)"
},
{
"key": "limit",
"value": "10",
"description": "Items per page (default: 10, max: 50)"
}
]
},
"description": "List all published posts with pagination. No authentication required."
},
"response": []
},
{
"name": "List Posts (Page 2)",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "{{base_url}}/api/posts?page=2&limit=5",
"host": ["{{base_url}}"],
"path": ["api", "posts"],
"query": [
{
"key": "page",
"value": "2"
},
{
"key": "limit",
"value": "5"
}
]
},
"description": "List posts - second page with 5 items per page."
},
"response": []
},
{
"name": "Get Post by ID",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "{{base_url}}/api/posts/{{post_id}}",
"host": ["{{base_url}}"],
"path": ["api", "posts", "{{post_id}}"]
},
"description": "Get a single post by ID. No authentication required."
},
"response": []
},
{
"name": "Update Post",
"request": {
"method": "PUT",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Authorization",
"value": "Bearer {{token}}"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"title\": \"Updated Blog Post Title\",\n \"content\": \"This content has been updated with new information.\"\n}"
},
"url": {
"raw": "{{base_url}}/api/posts/{{post_id}}",
"host": ["{{base_url}}"],
"path": ["api", "posts", "{{post_id}}"]
},
"description": "Update an existing post. Requires authentication and ownership."
},
"response": []
},
{
"name": "Update Post (Publish)",
"request": {
"method": "PUT",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Authorization",
"value": "Bearer {{token}}"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"published\": true\n}"
},
"url": {
"raw": "{{base_url}}/api/posts/{{post_id}}",
"host": ["{{base_url}}"],
"path": ["api", "posts", "{{post_id}}"]
},
"description": "Publish a draft post. Only updates the published field."
},
"response": []
},
{
"name": "Delete Post",
"request": {
"method": "DELETE",
"header": [
{
"key": "Authorization",
"value": "Bearer {{token}}"
}
],
"url": {
"raw": "{{base_url}}/api/posts/{{post_id}}",
"host": ["{{base_url}}"],
"path": ["api", "posts", "{{post_id}}"]
},
"description": "Soft delete a post. Requires authentication and ownership."
},
"response": []
}
],
"description": "Blog post CRUD endpoints"
},
{
"name": "Upload",
"item": [
{
"name": "Upload Image",
"request": {
"method": "POST",
"header": [
{
"key": "Authorization",
"value": "Bearer {{token}}"
}
],
"body": {
"mode": "formdata",
"formdata": [
{
"key": "file",
"type": "file",
"src": "",
"description": "Select a JPG, JPEG, PNG, or WebP image (max 5MB)"
}
]
},
"url": {
"raw": "{{base_url}}/api/upload",
"host": ["{{base_url}}"],
"path": ["api", "upload"]
},
"description": "Upload an image file. Requires authentication. Allowed types: jpg, jpeg, png, webp. Max size: 5MB."
},
"response": []
}
],
"description": "File upload endpoint"
},
{
"name": "Error Cases",
"item": [
{
"name": "Register - Invalid Email",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"email\": \"invalid-email\",\n \"password\": \"password123\"\n}"
},
"url": {
"raw": "{{base_url}}/api/auth/register",
"host": ["{{base_url}}"],
"path": ["api", "auth", "register"]
},
"description": "Test validation: invalid email format"
},
"response": []
},
{
"name": "Register - Short Password",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"email\": \"test2@example.com\",\n \"password\": \"short\"\n}"
},
"url": {
"raw": "{{base_url}}/api/auth/register",
"host": ["{{base_url}}"],
"path": ["api", "auth", "register"]
},
"description": "Test validation: password too short (min 8 chars)"
},
"response": []
},
{
"name": "Login - Wrong Password",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"email\": \"test@example.com\",\n \"password\": \"wrongpassword\"\n}"
},
"url": {
"raw": "{{base_url}}/api/auth/login",
"host": ["{{base_url}}"],
"path": ["api", "auth", "login"]
},
"description": "Test: wrong password returns 401"
},
"response": []
},
{
"name": "Create Post - No Auth",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"title\": \"Unauthorized Post\",\n \"content\": \"This should fail\",\n \"published\": true\n}"
},
"url": {
"raw": "{{base_url}}/api/posts",
"host": ["{{base_url}}"],
"path": ["api", "posts"]
},
"description": "Test: creating post without auth returns 401"
},
"response": []
},
{
"name": "Get Post - Not Found",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "{{base_url}}/api/posts/non-existent-id",
"host": ["{{base_url}}"],
"path": ["api", "posts", "non-existent-id"]
},
"description": "Test: getting non-existent post returns 404"
},
"response": []
},
{
"name": "Create Post - Empty Title",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Authorization",
"value": "Bearer {{token}}"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"title\": \"\",\n \"content\": \"Content without title\",\n \"published\": true\n}"
},
"url": {
"raw": "{{base_url}}/api/posts",
"host": ["{{base_url}}"],
"path": ["api", "posts"]
},
"description": "Test validation: empty title returns 400"
},
"response": []
}
],
"description": "Test error cases and validation"
}
]
}