User Search API Documentation

Overview

The User Search API allows users to search for other users and retrieve detailed information about specific users. It supports pagination and filtering by user attributes such as first name and last name. The API also provides counts of followers and following for each user.

Note: Ensure that all API requests include a valid JSON Web Token (JWT) in the x-token header to authenticate users.

Endpoints

GET /api/users

Retrieve a list of users with optional search and pagination. You can filter users based on the search query for their first name or last name. The results include counts of followers and following.

Request Headers:

x-token: <JWT>

Query Parameters:

page: number (default: 1)
limit: number (default: 10)
search: string (optional, search by first or last name)

Response:

{
  "users": [
    {
      "_id": "string",
      "firstName": "string",
      "lastName": "string",
      "email": "string",
      "birthday": "ISODate",
      "gender": "string",
      "role": "string",
      "profileImage": "string",
      "isPrivate": "boolean",
      "following": [
        "userId"
      ],
      "followers": [
        "userId"
      ],
      "followRequests": [
        "userId"
      ],
      "followingCount": "number",
      "followersCount": "number"
    }
  ],
  "totalPages": 5,
  "currentPage": 1
}

GET /api/users/:userId

Retrieve detailed information about a specific user by their user ID. The response includes user details and counts of followers and following.

Request Headers:

x-token: <JWT>

Response:

{
  "_id": "string",
  "firstName": "string",
  "lastName": "string",
  "email": "string",
  "birthday": "ISODate",
  "gender": "string",
  "role": "string",
  "profileImage": "string",
  "isPrivate": "boolean",
  "following": [
    "userId"
  ],
  "followers": [
    "userId"
  ],
  "followRequests": [
    "userId"
  ],
  "followingCount": "number",
  "followersCount": "number"
}

Pagination and Query Parameters

The GET /api/users endpoint supports pagination using the page and limit query parameters. You can also use the search parameter to filter users based on their first or last name.

Example Query for Pagination and Search:

GET /api/users?page=2&limit=10&search=John

Retrieves the second page of users, with 10 users per page, whose first or last name contains "John".

Note: Ensure proper error handling for cases where users are not found or other server errors occur.

Notice: Search functionality for posts and videos is not yet supported. This feature will be added in a future update.