Skip to content

feat: Add HTTP API to export captured network logs#526

Open
abdullahsohailcs wants to merge 7 commits into
openflocon:mainfrom
abdullahsohailcs:feature/network-logs-json-export
Open

feat: Add HTTP API to export captured network logs#526
abdullahsohailcs wants to merge 7 commits into
openflocon:mainfrom
abdullahsohailcs:feature/network-logs-json-export

Conversation

@abdullahsohailcs
Copy link
Copy Markdown

Summary

Adds a built-in HTTP export API to the Flocon desktop server, allowing
external tools (test frameworks, CI pipelines, scripts) to query captured
network logs directly over HTTP without opening the desktop UI.

Endpoints

All endpoints are served on the existing HTTP server (port 9024).

Method Endpoint Description
GET /api/network-logs All captured network calls across all devices
GET /api/network-logs/{deviceId} All calls for a specific device
GET /api/network-logs/{deviceId}/filter Calls filtered by device and time range

Query Parameters (endpoint 3)

Parameter Type Description
startTimestamp Long (Unix ms) Return calls at or after this time
endTimestamp Long (Unix ms) Return calls at or before this time

Example Response

{
  "data": [
    {
      "callId": "7b6f09e6-...",
      "method": "GET",
      "url": "https://api.example.com/endpoint",
      "startTime": 1779192773561,
      "startTimeFormatted": "17:12:53.561",
      "statusCode": 200,
      "durationMs": 398.84,
      "requestHeaders": { "Authorization": "Bearer ..." },
      "responseHeaders": { "Content-Type": "application/json" },
      "requestBody": null,
      "responseBody": "{ ... }",
      "contentType": "application/json",
      "deviceId": "87b5d37fd3c32ce3",
      "appInstance": 1780479786702
    }
  ],
  "metadata": {
    "exportedAt": 1779200000000,
    "totalItems": 1,
    "filteredBy": {
      "deviceId": "87b5d37fd3c32ce3",
      "startTimestamp": 1779192773000,
      "endTimestamp": 1779199999999
    }
  }
}

abdullahsohailcs and others added 6 commits June 3, 2026 15:21
…mestamp filtering

- Create NetworkLogsExportModel data classes with serialization support
- Implement ExportNetworkLogsAsJsonUseCase for filtering network logs
- Add GET /api/export/network-logs endpoint with query parameter filtering
- Support filtering by deviceId, startTimestamp, and endTimestamp
- Return JSON response with metadata about exported data
… network export endpoint

- Add NetworkRepository as a dependency to ServerJvm
- Update Server.desktop.kt to pass networkRepository to ServerJvm constructor
- Integrate networkExportRoutes into the HTTP routing
- Update HTTP server initialization to include the new export endpoint
- Add GET /api/network-logs to fetch all captured network calls across all devices
- Add GET /api/network-logs/{deviceId} to fetch calls for a specific device
- Add GET /api/network-logs/{deviceId}/filter?startTimestamp=&endTimestamp= for time-range filtering
- Add getAllRequests/getAllRequestsByDevice DAO queries reading deviceId directly from DB
- Propagate getAllNetworkCalls(deviceId?) through NetworkLocalDataSource, NetworkRepository, and NetworkRepositoryImpl
- Fix Koin circular dependency (NetworkRepositoryImpl -> NetworkRemoteDataSourceImpl -> Server -> NetworkRepository) by using Lazy<NetworkRepository> in ServerJvm
- Use respondText with manual JSON serialization to avoid requiring ContentNegotiation plugin
- Fix deprecated dayOfMonth/monthNumber in TimeFormatter

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a feature to export network logs, adding new Ktor API endpoints under /api/network-logs along with corresponding Room database queries, data sources, and a new use case (ExportNetworkLogsAsJsonUseCase). Key feedback points out a compilation error in TimeFormatter.kt due to invalid datetime properties, suggests returning an empty list instead of a failure when no logs match the filter, advises using a proper serializer instead of manual JSON string interpolation for error responses, and recommends performing timestamp filtering at the database level rather than in memory to prevent performance bottlenecks.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

- Add startTimestamp/endTimestamp params to FloconNetworkDao queries so
  time-range filtering happens at DB level instead of in memory,
  preventing high memory usage on large datasets
- Thread startTimestamp/endTimestamp through NetworkLocalDataSource,
  NetworkLocalDataSourceRoom, NetworkRepository, and NetworkRepositoryImpl
- Remove in-memory timestamp filter from NetworkExportEndpoint
- Replace fragile string-interpolated error JSON with MapSerializer
  to safely handle special characters in error messages
- Revert TimeFormatter to dayOfMonth/monthNumber as day/month.number
  do not exist in the project's kotlinx.datetime version

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Copy link
Copy Markdown
Author

@abdullahsohailcs abdullahsohailcs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added improvements please check now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant