appwrite-utils
Version:
`appwrite-utils` is a comprehensive TypeScript library designed to streamline the development process for Appwrite projects. It provides a suite of utilities and helper functions that facilitate data manipulation, schema management, and seamless integrati
51 lines (50 loc) • 1.24 kB
JavaScript
export class AppwriteRequest {
headers;
method;
host;
scheme;
query;
queryString;
port;
url;
path;
_bodyBinary;
constructor(data) {
this.headers = data.headers || {};
this.method = data.method || "GET";
this.host = data.host || "localhost";
this.scheme = data.scheme || "http";
this.query = data.query || {};
this.queryString = data.queryString || "";
this.port = data.port;
this.url = data.url || "";
this.path = data.path || "/";
this._bodyBinary = data.bodyBinary || Buffer.alloc(0);
}
get contentType() {
return this.headers["content-type"] || "";
}
get bodyBinary() {
return this._bodyBinary;
}
get bodyText() {
return this._bodyBinary.toString("utf8");
}
get bodyJson() {
try {
return JSON.parse(this.bodyText);
}
catch {
return null;
}
}
get bodyRaw() {
return this.bodyText;
}
get body() {
if (this.contentType.startsWith("application/json")) {
return this.bodyBinary.length > 0 ? this.bodyJson : {};
}
return this.bodyText;
}
}