HttpPlugin
This file defines the HttpPlugin
class, which implements the HTTP plugin for the @sodacore/core
framework. The plugin loads its metadata from package.json
and registers all necessary HTTP services and providers with the application, enabling RESTful API development with Sodacore.
Features
- Automatic Metadata Loading: Reads plugin metadata (name, version, description, author) from
package.json
at runtime. - Service Registration: Registers the HTTP service and SSE connections provider with the application during installation.
- Extends BasePlugin: Inherits from
BasePlugin
for consistent plugin lifecycle and configuration handling. - Default Configuration: Provides a default configuration with port
8080
if none is supplied.
Usage
typescript
import HttpPlugin from './module/plugin';
import Application from '@sodacore/core';
const app = new Application();
const httpPlugin = new HttpPlugin();
await httpPlugin.install(app);
API
Properties
- name: The plugin name, loaded from
package.json
. - version: The plugin version, loaded from
package.json
. - description: The plugin description, loaded from
package.json
. - author: The plugin author, loaded from
package.json
. - dependencies: An array of plugin dependencies (empty by default).
Constructor
typescript
constructor(protected config: IConfig = { port: 8080 })
- config: Optional configuration object for the plugin, defaults to port 8080.
Methods
async install(app: Application): Promise<void>
Registers the HTTP service and SSE connections provider with the Sodacore application instance:
SseConnectionsProvider
HttpService
How It Works
- Loads plugin metadata from
package.json
using Bun's file API. - Sets the plugin's metadata properties.
- On installation, registers the HTTP service and SSE connections provider with the Sodacore application.
Notes
- This plugin is designed to be used with the Sodacore framework and expects Bun as the runtime.
- Throws an error if
package.json
is not found. - All HTTP-related functionality is encapsulated and registered via the
install
method. - Enables RESTful API development and SSE support out of the box.