oRPC

Functions

Public API reference for the oRPC extension

Extension Entry Points

FunctionDescription
NewExtension(opts ...ConfigOption) forge.ExtensionCreate the oRPC extension with functional options
NewExtensionWithConfig(config Config) forge.ExtensionCreate the oRPC extension with a complete config
DefaultConfig() ConfigReturns the default configuration

ORPC Interface -- Method Registration

MethodDescription
RegisterMethod(method Method) errorRegister a JSON-RPC method manually
GetMethod(name) (*Method, error)Get a registered method by name
ListMethods() []MethodList all registered methods
GenerateMethodFromRoute(route) (*Method, error)Generate a method from a Forge HTTP route

ORPC Interface -- Request Handling

MethodDescription
HandleRequest(ctx, request) *ResponseProcess a single JSON-RPC request
HandleBatch(ctx, requests) []*ResponseProcess a batch of JSON-RPC requests

ORPC Interface -- Schema

MethodDescription
OpenRPCDocument() *OpenRPCDocumentGenerate the OpenRPC schema document

ORPC Interface -- Middleware and Stats

MethodDescription
Use(middleware...)Add middleware to the processing pipeline
GetStats() *ServerStatsGet server statistics
SetRouter(router)Set the Forge router for route execution

Response Helpers

FunctionDescription
NewSuccessResponse(id, result) *ResponseCreate a success response
NewErrorResponse(id, code, message) *ResponseCreate an error response
NewErrorResponseWithData(id, code, message, data) *ResponseCreate an error response with additional data
GetErrorMessage(code) stringGet the standard message for a JSON-RPC error code

Key Types

Method

FieldTypePurpose
NamestringMethod name (e.g. create.users)
DescriptionstringHuman-readable description
HandlerMethodHandlerFunction to execute
Params*ParamsSchemaParameter schema
Result*ResultSchemaResult schema
Tags[]stringCategorization tags

Request

FieldTypePurpose
JSONRPCstringProtocol version (always "2.0")
MethodstringMethod name to invoke
Paramsjson.RawMessageMethod parameters
IDanyRequest identifier

Response

FieldTypePurpose
JSONRPCstringProtocol version
ResultanySuccess result
Error*ErrorError object (if failed)
IDanyRequest identifier

How is this guide?

On this page