Skip to content

Improvements to the REST API#70

Merged
satta merged 6 commits intomasterfrom
rest-improvements
Jul 9, 2025
Merged

Improvements to the REST API#70
satta merged 6 commits intomasterfrom
rest-improvements

Conversation

@satta
Copy link
Member

@satta satta commented Jul 7, 2025

This PR introduces changes to extend the functionality of the REST API to match the filtering capabilities of the GraphQL API beyond the original CIRCL API.

The PR also introduces simple offset/limit pagination. The pagination is not optimized as in actually changing the backend-facing protocol to have the server optimize the query according to a given cursor (which is probably not too difficult to do but would change the protocol).
Instead, the scope of the queries towards the backend is adjusted.

@satta satta force-pushed the rest-improvements branch from f0bbc91 to eefed62 Compare July 7, 2025 21:36
@satta satta requested review from 0mbi and Copilot July 9, 2025 11:31
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR extends the REST API to fully mirror GraphQL–style filtering (limit/offset pagination, rrtype and sensor ID filters) and updates tests, helper functions, and module settings to support these features.

  • Added URL parameter parsing and pagination logic in query/query_rest.go
  • Extended test suite in query/query_rest_test.go for rrtype, sensor ID, and pagination
  • Updated module Go version and cleaned up dependencies
  • Enhanced dummy DB search to honor rrtype and sensor ID filters

Reviewed Changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
scripts/mkjson.py Switched to python3 shebang and fixed missing .encode() on text before hashing
query/query_rest_test.go Expanded makeRESTQuery signature; added tests for pagination, sensor IDs, and RR types; replaced ioutil with io
query/query_rest.go Introduced parseParams, limitSlice, and updated ServeHTTP to apply new filters and pagination
go.mod Bumped Go toolchain to 1.23; reorganized and expanded require blocks
db/db_dummy.go Improved MockDB.Search to filter by sensor ID and RR type

return
offParams, ok := r.URL.Query()["next"]
if ok && len(offParams[0]) > 0 {
offVal, err := strconv.ParseUint(offParams[0], 10, 32)
Copy link

Copilot AI Jul 9, 2025

Choose a reason for hiding this comment

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

Similarly, parse the offset with 64-bit size (ParseUint(..., 10, 64)) to avoid silently truncating larger values.

Suggested change
offVal, err := strconv.ParseUint(offParams[0], 10, 32)
offVal, err := strconv.ParseUint(offParams[0], 10, 64)

Copilot uses AI. Check for mistakes.
@0mbi
Copy link
Contributor

0mbi commented Jul 9, 2025

Accepting merge request.

  • deeply nested ifs are accepted because it is db_dummy and not running in production.
  • four return values parseParams acceptable because it is not used a lot

Copy link
Contributor

@0mbi 0mbi left a comment

Choose a reason for hiding this comment

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

see comments

@satta satta merged commit 536cb2b into master Jul 9, 2025
6 checks passed
@satta satta deleted the rest-improvements branch July 9, 2025 12:50
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.

3 participants