Skip to main content

Overview

The HTTP API adapter allows applications to interact with NapCat by sending HTTP requests. It supports both standard HTTP endpoints and WebSocket connections over the same port.

Configuration

Configure the HTTP server in your OneBot config:

Configuration Options

Making Requests

Basic Request

Make API calls by sending HTTP requests to http://host:port/action_name:

GET Requests

You can also use GET requests with query parameters:

Authentication

NapCat supports two authentication methods:

2. Query Parameter

Response Format

All API responses follow the OneBot 11 standard format:

Success Response

Error Response

Common Status Codes

WebSocket on HTTP Port

When enableWebsocket is enabled, you can connect to WebSocket on the same port:
See the WebSocket documentation for more details.

Echo Parameter

Include an echo field in your request to track responses:
The response will include the same echo value:

Request Body Format

NapCat accepts:
  • Standard JSON (application/json)
  • URL-encoded form data (application/x-www-form-urlencoded)
  • JSON5 format (relaxed JSON syntax)
  • Requests without Content-Type header (auto-detected as JSON)

Multiple HTTP Servers

You can run multiple HTTP servers on different ports:

Implementation Details

The HTTP adapter is implemented in packages/napcat-onebot/network/http-server.ts and uses:
  • Express.js for HTTP routing
  • CORS support for cross-origin requests
  • Support for request bodies up to 5000MB
  • Automatic JSON5 parsing for flexible syntax

Best Practices

  1. Always use authentication - Set a strong token in production
  2. Use HTTPS in production - Place NapCat behind a reverse proxy with SSL
  3. Bind to localhost - Use 127.0.0.1 unless you need external access
  4. Enable CORS carefully - Only enable if you need browser access
  5. Monitor the debug logs - Set debug: true during development

Next Steps