Protected
parserProtected
requestConverts the Data
object into a plain JSON representation, including all
properties defined as getters in the subclass.
The toJSON
method dynamically identifies getter properties in the
subclass and collects their values to construct a JSON object. This is
particularly useful when you want to serialize the Data
object for APIs,
logging, or other use cases requiring JSON format.
A plain object representing the Data
instance with all getter properties.
class LoginData extends Data<FormParser> {
get username() {
return this.parser.getString("username");
}
get password() {
return this.parser.getString("password");
}
}
const loginData = new LoginData(new FormParser(formData));
console.log(JSON.stringify(loginData.toJSON()));
// Output: { "username": "johndoe", "password": "secret" }
Entity that represents the geographical information of the client's request. This information is provided by Cloudflare Workers and is accessible through the
request.cf
object.Example