create library

Classes

H4Event
Represents an HTTP request event in the H4 framework.

Functions

createApp({int port = 3000, bool autoStart = true, Middleware? onRequest, ErrorHandler? onError, Middleware? afterResponse}) → H4
Constructs an instance of the H4 class, which is the main entry point for your application.
createRouter() → H4Router
Create a router instance for mapping requests.
detectEncoding(Uint8List bytes) String
getRequestHost(H4Event event) String?
Get incoming request host
getRequestIp(H4Event event) String?
getRequestProtocol(H4Event event) → dynamic
Get the request protocol.
getRequestUrl(H4Event event) String?
Get the entire incoming URL.
getResponseHeader(H4Event event, String header) String?
Retrieves the value of a specific header in the HTTP response from an H4Event instance.
getResponseHeaders(H4Event event) HttpHeaders?
Get the outgoing response headers.
getRouteParam(H4Event event, {required String name}) String?
Gets a route parameter value by name from the event.
handleCors(H4Event event, {String origin = "*", String methods = "GET, POST, PUT, DELETE, OPTIONS, HEAD, PATCH", String headers = "Content-Type, Authorization, X-Requested-With", bool credentials = false, int maxAge = 86400}) → void
Handles Cross-Origin Resource Sharing (CORS) headers for HTTP requests.
parseBodyAsJson({required List<int> bytes}) → dynamic
parseJsonString(String jsonString) FutureOr<Either<Map?, List?>?>
parseRequestBody(HttpRequest request, {Duration timeout = const Duration(seconds: 360)}) Future
readFiles(H4Event event, {required String fieldName, String? customFilePath, bool hashFileName = false, int maxFileSize = 10}) Future<List<Map<String, dynamic>>?>
Reads file(s) from a multipart/form-data request for a specific field name.
readFormData(dynamic event) Future<FormData>
readRequestBody(H4Event event) Future
Read the body of the incoming event request. Returns the request body either as parsed json or a string.
setResponseHeader(H4Event event, {required String header, required String value}) → dynamic
Set the value of outgoing response header

Exceptions / Errors

CreateError
Handles a specific type of error, CreateError when it is thrown explicitly in a catch block