Legalese-Node-LN1

Query Interface Documentation

The Query Interface module provides a secure and efficient way for users and applications to interact with the DataHive legal data ecosystem. This interface allows for querying legal documents, metadata, and insights generated from the processing pipeline. The Query Interface is designed to support both RESTful API calls and WebSocket connections for real-time data retrieval.

Core Features

API Endpoints

Base URL

https://api.datahive.com/v1/query

Authentication

All API requests require authentication using an API key:

Authorization: Bearer YOUR_API_KEY

Endpoints

1. Retrieve Document

GET /documents/{documentId}
Authorization: Bearer <token>

Response Format

{
    "status": "success",
    "data": {
        "id": "string",
        "title": "string",
        "content": "string",
        "metadata": {
            "jurisdiction": "string",
            "type": "string",
            "created_at": "ISO8601"
        }
    }
}

2. Search Documents

GET /documents/search?query={searchTerm}&limit={number}
Authorization: Bearer <token>

Query Parameters

Response Format

{
    "status": "success",
    "data": [
        {
            "id": "string",
            "title": "string",
            "snippet": "string"
        }
    ],
    "pagination": {
        "currentPage": 1,
        "totalPages": 10,
        "totalItems": 100,
        "itemsPerPage": 10
    }
}

3. Fetch Metadata

GET /documents/{documentId}/metadata
Authorization: Bearer <token>

Response Format

{
    "status": "success",
    "data": {
        "id": "string",
        "metadata": {
            "jurisdiction": "string",
            "type": "string",
            "author": "string",
            "created_at": "ISO8601"
        }
    }
}

WebSocket Connection

Real-Time Updates

To receive real-time updates about document status or new submissions:

const ws = new WebSocket('wss://api.datahive.com/v1/query/ws');

ws.onopen = () => {
    console.log('WebSocket connection established');
};

ws.onmessage = (event) => {
    const data = JSON.parse(event.data);
    console.log('Received update:', data);
};

Subscribe to Document Updates

To subscribe to updates for specific documents:

{
    "action": "subscribe",
    "documentId": "{documentId}"
}

Rate Limiting

Error Handling

Common error codes include:

Error Response Format

{
    "status": "error",
    "error": {
        "code": "string",
        "message": "string"
    }
}

Conclusion

The Query Interface is a powerful tool for accessing and interacting with legal data within the DataHive ecosystem. By providing both RESTful and WebSocket capabilities, it allows users to efficiently retrieve documents, access metadata, and receive real-time updates. For further details on implementation and best practices, please refer to the API Documentation and Integration Guide.