Request Response
The Request object is used to retrieve client request information. The Response object is used to send information back to the client.
Request
It provides methods to access the current QueryString or Form data. If no specific channel is specified, it will search for the values in multiple sources, including QueryString, Form, Headers, Cookie, and JSON Body. Here's an example code:
k.request.fieldName;
k.request.form.keys;
k.request.queryString.keys;
k.request.queryString.FieldName;
k.request.files[0].fileName;
Request object also provides access to common request headers, such as:
k.request.clientIp;
k.request.host;
k.request.method;
k.request.ur;
Response
The Response object in Kooboo is used to send information back to the client. It allows you to return various types of data, including text (which can include JSON data) or binary data. The Response object provides multiple overloads for handling binary data.
k.response.json(obj);
k.response.write("Hello World");
k.response.binary(contentType: string, bytes: number[], filename: string): void
Redirect or Set Header
k.response.redirect("https://www.kooboo.com");
k.response.statusCode = 301;
k.response.setHeader("Company", "Kooboo");
Set Page Title or Meta contents
k.response.meta.title = "test title";
k.response.meta.setMeta("keywords", "my website keywords");
k.response.meta.setMeta(Name: string, content: string): void
Execute remote data or execute Kooboo code.
k.response.execute("/contentOfOtherPage");
k.response.renderView("<div>view body</div>");