API

Votes API

Endpoints for adding and removing votes on feature requests.

Toggle Vote

Add or remove a vote on a feature. If the user has already voted, the vote is removed. Otherwise, a new vote is added.

POST/api/features/{feature_id}/vote

Headers

Content-Type: application/json
x-user-id: {user_id}
x-user-name: {user_name}
x-user-email: {user_email} (optional)

Response (Vote Added)

200 OK
{
  "voted": true,
  "vote_count": 25
}

Response (Vote Removed)

200 OK
{
  "voted": false,
  "vote_count": 24
}

How Voting Works

  • One Vote Per UserEach user can only vote once per feature
  • Idempotent ToggleCalling the endpoint again toggles the vote
  • Auto Vote on CreateThe creator of a feature automatically votes for it
  • Real-time CountsVote counts are returned in real-time with each response

Example Usage

JavaScript/TypeScript

vote.ts
async function toggleVote(featureId: string) {
  const response = await fetch(
    `https://reqflow.com/api/features/${featureId}/vote`,
    {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        'x-user-id': userId,
        'x-user-name': userName,
      },
    }
  );

  const data = await response.json();
  console.log(`Voted: ${data.voted}, Total votes: ${data.vote_count}`);
}

Swift

VoteManager.swift
func toggleVote(featureId: String) async throws {
    var request = URLRequest(
        url: URL(string: "https://reqflow.com/api/features/\(featureId)/vote")!
    )
    request.httpMethod = "POST"
    request.setValue("application/json", forHTTPHeaderField: "Content-Type")
    request.setValue(userId, forHTTPHeaderField: "x-user-id")
    request.setValue(userName, forHTTPHeaderField: "x-user-name")

    let (data, _) = try await URLSession.shared.data(for: request)
    let result = try JSONDecoder().decode(VoteResponse.self, from: data)
    print("Voted: \(result.voted), Count: \(result.voteCount)")
}

Kotlin

VoteRepository.kt
suspend fun toggleVote(featureId: String) {
    val url = "https://reqflow.com/api/features/$featureId/vote"
    val request = Request.Builder()
        .url(url)
        .post(RequestBody.create(null, ByteArray(0)))
        .header("Content-Type", "application/json")
        .header("x-user-id", userId)
        .header("x-user-name", userName)
        .build()

    val response = client.newCall(request).execute()
    val result = Json.decodeFromString<VoteResponse>(response.body?.string() ?: "")
    println("Voted: ${result.voted}, Count: ${result.voteCount}")
}