WebRequest class
The WebRequest
class handles HTTP requests and provides various methods
for processing, routing, and responding to client requests. It includes
methods for parsing request data, managing sessions, handling cookies,
rendering views, redirecting, and more.
Constructors
- WebRequest(HttpRequest _rq)
- Constructor to initialize the WebRequest with the given HttpRequest.
Properties
- assetManager → AssetManager
-
Manages assets like JavaScript and CSS for rendering.
latefinal
-
currently it just support the Basic Authentication
You can develop the
Authorization
class.no setter -
Provides access to the list of cookies included in the request.
no setter
- cssRenderId ↔ String
-
CSS render ID for asset management.
getter/setter pair
- dataJsId ↔ String
-
Data JavaScript render ID for asset management.
getter/setter pair
- endpoint → String
-
Gets the current endpoint, normalized for slashes.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- headers → HttpHeaders
-
Provides access to the HTTP headers included in the request.
no setter
- host → String
-
Retrieves the current hostname from the request URI.
no setter
- httpRequest → HttpRequest
-
Provides access to the underlying HttpRequest.
no setter
- isApiEndpoint → bool
-
Checks if the current endpoint starts with 'api/'.
no setter
- isClosed ↔ bool
-
Indicates whether the response has been closed.
getter/setter pair
- jsRenderId ↔ String
-
JavaScript render ID for asset management.
getter/setter pair
- method → String
-
Provides access to the HTTP method (e.g., GET, POST) used in the request.
no setter
- port → int
-
no setter
- response → HttpResponse
-
Provides access to the response associated with the request.
no setter
- route ↔ WebRoute?
-
The route associated with the request, if any.
getter/setter pair
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- session → HttpSession
-
Provides access to the session associated with the request.
no setter
- stream → HttpRequest
-
Provides access to the request stream.
no setter
- uri → Uri
-
Provides access to the URI of the request.
no setter
Methods
-
addAsset(
Asset asset) → AssetManager - Adds a single asset to the asset manager.
-
addAssets(
List< Asset> assets) → AssetManager - Adds a list of assets to the asset manager.
-
addCookie(
String key, String value, {Duration? duration, bool safe = true}) → dynamic - Adds or updates a cookie in the response.
-
addParam(
String key, Object? param) → WebRequest - Adds a single parameter to the request.
-
addParams(
Map< String, Object?> params) → WebRequest - Adds multiple parameters to the request.
-
addSession(
String key, Object value) → dynamic - Adds a value to the session.
-
addValidator(
String formName, Map< String, dynamic> validator) → void - Adds a validator for a specific form.
-
changeLanguege(
String ln) → void -
Changes the language based on the given language code
ln
. -
checkForm(
[String? name]) → bool - Validates a form submission by checking the hidden form key and timestamp.
-
data(
String key, {String def = ''}) → String -
Retrieves the value associated with
key
from the request data. -
dataObject(
String key, {dynamic def}) → dynamic -
Retrieves the value associated with
key
as an object from the request data. -
dataType<
T> (String key, {T? def}) → T -
Retrieves the value associated with
key
from the request data, cast to typeT
. -
dump(
dynamic object) → Future< String> -
formChecker(
{String? name, bool inputHtml = true}) → String - Generates a form checker hidden input field or a random key for form validation.
-
generateRandomString(
[int length = 8]) → String - Generates a random alphanumeric string of a specified length.
-
get<
T> (String key, {T? def}) → T -
Retrieves the value of
key
cast to typeT
. Supports type-specific operations. -
getAllData(
) → Map< String, Object?> - Retrieves all parsed request data including GET, POST, and FILE data.
-
getAllSession(
) → Object - Retrieves all session-related data.
-
getAssets(
) → List< Asset> - Retrieves the list of assets currently managed by the asset manager.
-
getCookie(
String key, {String def = '', bool safe = true}) → String - Retrieves a cookie value from the request.
-
getFile(
String key) → dynamic -
Retrieves file data associated with
key
from the request. -
getGlobalEvents(
) → Map< String, Object?> - Retrieves global events and parameters for rendering.
-
getHeaderFormData(
) → Future< Map> -
Retrieves form data from a
multipart/form-data
request. -
getIP(
) → String - Retrieves the client's IP address from the request headers or connection information.
-
getLanguage(
) → String - Retrieves the current language based on URI, session, or settings.
-
getParam(
String key, {Object? def}) → Object? - Retrieves the value of a parameter.
-
getParams(
) → Map< String, dynamic> - Retrieves all parameters as a map.
-
getSession(
String key, {Object? def = ''}) → Object - Retrieves a session value.
-
getValidator(
) → Map< String, Object?> - Retrieves the validators map.
-
hasData(
String key) → bool -
Checks if
key
exists in the request data. -
hasDataValue(
String key) → bool -
Checks if
key
exists and has a non-empty value in the request data. -
hasParam(
String key) → bool - Checks if a parameter exists.
-
init(
) → Future< WebRequest> - Initializes the request by setting response headers and parsing data.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
onClose(
String layout) → String - Handles tasks to be performed before closing the response.
-
parseData(
) → Future< Map> - Parses and returns request data from GET, POST, and file fields.
-
redirect(
String path, {int status = HttpStatus.movedTemporarily, bool checkApiPath = true}) → Future< String> - Redirects the response to the given path.
-
redirectNextUri(
Uri uri, {int status = HttpStatus.movedTemporarily, bool checkApiPath = true}) → Future< String> - Redirects the response to the given URI and waits for the redirect to complete.
-
redirectUri(
Uri uri, {int status = HttpStatus.movedTemporarily, bool checkApiPath = true}) → Future< String> - Redirects the response to the given URI.
-
removeCookie(
String key) → void - Removes a cookie by setting its value to an empty string and expiration to a past date.
-
removeParam(
String key) → WebRequest - Removes a parameter from the request.
-
render(
{required String path, Map< String, Object?> viewParams = const {}, bool isFile = true, bool toData = false, int status = 200}) → Future<String> - Renders a template with the given parameters and configuration.
-
renderData(
{required Map< String, Object?> data, int status = 200}) → Future<String> - Renders a map of data as JSON and sends it in the response.
-
renderDataParam(
{int status = 200, Map< String, Object?> data = const {}}) → Future<String> - Handles rendering of data with additional parameters and status code.
-
renderError(
int status, {Map< String, Object?> params = const {}, String message = '', bool toData = false}) → Future<String> - Renders an error view with the specified status and parameters.
-
renderHtml(
{required String html, int status = 200}) → Future< String> - Renders an HTML response.
-
renderListData(
{required List< Map< data, int status = 200}) → Future<String, Object?> >String> - Renders a list of data as JSON and sends it in the response.
-
renderSocket(
) → String - Renders a socket request. Currently, this method only returns a string. this mean it will make a fake string to wait for socket response.
-
renderString(
{required String text, int status = 200, ContentType? contentType}) → Future< String> - Renders a plain text response.
-
renderView(
{required String path, int status = 200, bool isFile = true, bool toData = false, Map< String, dynamic> data = const {}}) → Future<String> - after this function everything will be stop and send to client
-
setSetting(
Map< String, Object?> setting) → dynamic - Sets application-specific settings for the request.
-
toString(
) → String -
A string representation of this object.
inherited
-
tryData<
T> (String key, {T? def}) → T? -
Retrieves the value of
key
as a String from the request data. If the value is not found, returnsdef
(default value). This method is used to retrieve string values from the request data. -
url(
String subPath, {Map< String, String> ? params}) → String - Constructs a full URL by combining a base URL with a subpath and optional query parameters.
-
writeAndClose(
String layout) → Future -
Writes the
layout
to the response and closes it.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
-
operator [](
String key) → String -
Overloads the index operator to return the value for
key
using data.
Static Properties
-
localEvents
→ Map<
String, Object> -
Local events map for testing purposes.
final