create library

Classes

H4Event
Represents an HTTP request event in the H4 framework.

Properties

map Map<String, Type>
getter/setter pair

Functions

appendDefaultResponseHeader(HttpHeaders responseHeaders, ContentType headerValue) → void
convertToDouble(dynamic json) double
convertToList<T>(dynamic json, T itemConverter(dynamic)) List<T>
convertToMapStringInt(dynamic json) Map<String, int>
Common converter functions
convertToMapStringString(dynamic json) Map<String, String>
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) String?
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.
handleMultipartFormdata(HttpRequest request, String boundary, FormData formData) Future<FormData>
parseBodyAsJson<T>({required List<int> bytes}) → T?
parseBodyWithConverter<T>(List<int> bytes, JsonConverter<T> converter) → T?
Parse JSON body with custom type conversion
parseRequestBody<T>(HttpRequest request, {Duration timeout = const Duration(seconds: 360)}) FutureOr<T?>
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<T>(H4Event event) Future<T?>
Read the incoming HTTP event request body. Generically typed.
setResponseHeader(H4Event event, {required String header, required String value}) → dynamic
Set the value of outgoing response header

Typedefs

JsonConverter<T> = T Function(dynamic json)
Type converter function signature for converting JSON values

Exceptions / Errors

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