API Testing Documentation (Postman)

Base URL: https://api-testing.svlautomations.in/
Headers Required: Set Content-Type: application/json for all POST and PUT requests.

1. Public APIs (No Authentication Required)

GET /public_categories.php

Retrieve all categories. (Append ?id=1 to get a specific category).

Expected Response (200 OK)

[
    {
        "id": 1,
        "name": "Technology"
    }
]
POST /public_categories.php

Create a new category.

Request Body (JSON)

{
  "name": "Technology"
}

Expected Response (200 OK)

{
  "message": "Category created",
  "id": 1
}
PUT /public_categories.php

Update an existing category. Requires id in URL.

Request Body (JSON)

{
  "id": 1,
  "name": "Advanced Technology"
}

Expected Response (200 OK)

{
  "message": "Category updated"
}
DELETE /public_categories.php?id=1

Delete a category. Requires id in URL.

Expected Response (200 OK)

{
  "message": "Category deleted"
}
GET /public_blogs.php

Retrieve all blogs. (Append ?id=1 to get a specific blog).

Expected Response (200 OK)

{
  "id": 1,
  "title": "Technology Learning Postman",
  "content": "Postman is great for API testing...",
  "category_id": 1
}
POST /public_blogs.php

Create a blog publicly (no user attached).

Request Body (JSON)

{
  "title": "Learning Postman",
  "content": "Postman is great for API testing...",
  "category_id": 1
}

Expected Response (200 OK)

{
  "message": "Public blog created",
  "id": 1
}
PUT /public_blogs.php

Update a public blog. Requires id in URL.

Request Body (JSON)

{
  "id":1,
  "title": "Learning Postman Updated",
  "content": "Postman is excellent for API testing...",
  "category_id": 1
}

Expected Response (200 OK)

{
  "message": "Public blog updated"
}
DELETE /public_blogs.php?id=1

Delete a public blog. Requires id in URL.

Expected Response (200 OK)

{
  "message": "Public blog deleted"
}
GET /public_blogs_by_category.php?category_id=1

Read all blogs belonging to a specific category.

Expected Response (200 OK)

[
  {
    "id": 1,
    "title": "Learning Postman",
    "content": "...",
    "category_id": 1,
    "user_id": null
  }
]
GET /public_blogs_by_date.php?start_date=2023-01-01&end_date=2023-12-31

Read all blogs created between a specific date range.

Expected Response (200 OK)

[
  {
    "id": 1,
    "title": "Learning Postman",
    "created_at": "2023-10-15 14:30:00"
  }
]

2. Authentication

POST /register.php

Register a new user account.

Request Body (JSON)

{
  "username": "student1",
  "password": "password123"
}

Expected Response (200 OK)

{
  "message": "User registered successfully"
}
POST /login.php

Login to receive your Bearer token.

Request Body (JSON)

{
  "username": "student1",
  "password": "password123"
}

Expected Response (200 OK)

{
  "message": "Login successful",
  "token": "a1b2c3d4e5f6g7h8i9j0"
}

3. Protected APIs (Requires Token)

Important: For all endpoints below, you must go to the Authorization tab in Postman, select Bearer Token, and paste the token received from the Login API.
POST /auth_blogs.php Requires Auth

Create a blog tied to the currently logged-in user.

Request Body (JSON)

{
  "title": "My First Secure Blog",
  "content": "This is protected by a token.",
  "category_id": 1
}

Expected Response (200 OK)

{
  "message": "Auth blog created",
  "id": 2
}
PUT /auth_blogs.php?id=2 Requires Auth

Update a blog (User can only update their own blogs). Requires id in URL.

Request Body (JSON)

{
  "title": "Updated Secure Blog",
  "content": "Updated content here.",
  "category_id": 1
}

Expected Response (200 OK)

{
  "message": "Auth blog updated"
}
DELETE /auth_blogs.php?id=2 Requires Auth

Delete a blog (User can only delete their own blogs). Requires id in URL.

Expected Response (200 OK)

{
  "message": "Auth blog deleted"
}
GET /auth_my_blogs.php Requires Auth

Read all blogs written by the logged-in user.

Expected Response (200 OK)

[
  {
    "id": 2,
    "title": "Updated Secure Blog",
    "content": "Updated content here.",
    "category_id": 1,
    "user_id": 5,
    "created_at": "2023-10-15 15:00:00"
  }
]