Skip to content

Feature Request: Version-Based API Query and Batch Requests for JSON-RPC 2.0 #2808

Open
@lithbitren

Description

@lithbitren

Hi docs.rs team,

This API will provide precise, secure, and efficient metadata access for LLMs and tools, addressing the above issues.

I suggest adding the following JSON-RPC 2.0 APIs to improve metadata query precision and efficiency:

Core Requirements

  1. Query API Documentation by Version
    Method Name: get_api_documentation

Parameters:

crate_name (required): Name of the crate (string).
version (optional): Specific version (string). If omitted, the latest version is used.
Example Request (with version):

{  
  "jsonrpc": "2.0",  
  "method": "get_api_documentation",  
  "params": {  
    "crate_name": "serde",  
    "version": "1.0.0"  
  },  
  "id": 1  
}  

Success Response (valid crate and version):

{  
  "jsonrpc": "2.0",  
  "result": {  
    "crate_name": "serde",  
    "version": "1.0.0",  
    "api_documentation": [  
      {  
        "name": "Serializer",  
        "description": "Serialization struct",  
        "parameters": [...]  
      }  
    ]  
  },  
  "id": 1  
}  

Error Responses:

Crate does not exist:

{  
  "jsonrpc": "2.0",  
  "error": {  
    "code": -32001,  
    "message": "Crate 'nonexistent_crate' does not exist"  
  },  
  "id": 1  
}  

Invalid version:

{  
  "jsonrpc": "2.0",  
  "error": {  
    "code": -32002,  
    "message": "Version '2.0.0' for crate 'serde' is invalid"  
  },  
  "id": 1  
}

API not found:

{  
  "jsonrpc": "2.0",  
  "error": {  
    "code": -32003,  
    "message": "API 'invalid_api' not found in crate 'serde' v1.0.0"  
  },  
  "id": 1  
}  
  1. Fuzzy Search with Pagination
    Method Name: search_api

Parameters:

query (required): Search keyword (string).
limit (optional): Number of results (default 10, max 200).
offset (optional): Pagination offset (default 0).
Example Request:

{  
  "jsonrpc": "2.0",  
  "method": "search_api",  
  "params": {  
    "query": "serde",  
    "limit": 5  
  },  
  "id": 2  
}  

Success Response:

{  
  "jsonrpc": "2.0",  
  "result": [  
    {  
      "crate_name": "serde",  
      "version": "1.0.0",  
      "api_name": "Serializer",  
      "description": "..."  
    },  
    ...  
  ],  
  "id": 2  
}
  1. Batch Requests
    Example Request:
[  
  {  
    "jsonrpc": "2.0",  
    "method": "get_api_documentation",  
    "params": {  
      "crate_name": "serde"  
    },  
    "id": 1  
  },  
  {  
    "jsonrpc": "2.0",  
    "method": "search_api",  
    "params": {  
      "query": "rust"  
    },  
    "id": 2  
  }  
]

Response Format:

[  
  {  
    "jsonrpc": "2.0",  
    "result": { ... },  
    "id": 1  
  },  
  {  
    "jsonrpc": "2.0",  
    "result": [ ... ],  
    "id": 2  
  }  
]  

Key Advantages
Reduce Resource Usage:
Precise queries avoid parsing full HTML pages.
Batch requests lower network overhead.
Improve Accuracy:
Version control ensures documentation matches the requested version.
Standard error codes (e.g., -32001) simplify error handling.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-backendArea: Webserver backendE-hardEffort: This will require a lot of workP-lowLow priority issues

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions