Gathering detailed insights and metrics for z-http
Gathering detailed insights and metrics for z-http
Gathering detailed insights and metrics for z-http
Gathering detailed insights and metrics for z-http
npm install z-http
Typescript
Module System
Node Version
NPM Version
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
3
this is a part of ZadaheaD's owner core tools for easier much more efficiant way to work with HTML, CSS, and Javascripts
look at z-views, if you want a lightweight "ejs like" server-side rendering engine
I never liked working with ejs, or these kind of tools cos I find them very messy, and I always liked working as clean and as seperated as possible. so in this project, I will use the same logic as ejs but with much cleaner way to handle HTML files and manipulate JS objects.
This documentation is designed to start a project from scratch with nothing but npm init
the first thing to install is the http-server for the project.
z-http is designed for building web applications and APIs.
To install, run npm install for your package.json dependencies:
1npm install z-http
1var http = require('z-http');
1http.start(3000, function (route, method) { 2 return (data, callback) => { 3 callback(`Hello World`); 4 } 5}, { 6//params will go here 7});
response for: http://localhost:3000/
1Hello World
1var http = require('z-http'); 2 3http.start(3000, function (route, method) { 4 return (data, callback) => { 5 callback(` 6 A ${method.toUpperCase()} request 7 for <b>/${route}</b> route 8 has been called. <br /> 9 10 payload: ${JSON.stringify(data.payload)} <br /> 11 querystring: ${JSON.stringify(data.querystring)} 12 `); 13 } 14}, {});
response for: http://localhost:3000/home?hello=world
1A GET request for /home route has been called. 2payload: {} 3querystring: {"hello":"world"}
validation
parameter1var http = require('z-http'); 2 3http.start(3000, function (route, method) { 4 return (data, callback) => { 5 callback(` 6 A ${method.toUpperCase()} request 7 for <b>/${route}</b> route 8 has been called. <br /> 9 10 payload: ${JSON.stringify(data.payload)} <br /> 11 querystring: ${JSON.stringify(data.querystring)} 12 `); 13 } 14}, { 15 validation: function (data, callback) { 16 17 this.data = data; 18 this.callback = callback; 19 20 this.trig = () => { 21 //=>> validate request here 22 console.log("headers", data.headers); 23 console.log("cookies", data.cookies); 24 25 console.log("querystring", data.querystring); 26 console.log("payload", data.payload); 27 28 //if valid 29 //callback(data); 30 31 //if not valid 32 callback(data, {}, errorRoute); 33 } 34 } 35}); 36 37const errorRoute = (data, callback) => { 38 //fallback function for error requests 39 callback("this is an unauthorized request", http.STATUS.UNAUTHORIZED) 40}
1var http = require('z-http'); 2 3http.start(3000, function (route, method) { 4 return (data, callback) => { 5 callback(` 6 A ${method.toUpperCase()} request 7 for <b>/${route}</b> route 8 has been called. <br /> 9 10 decoded data: ${JSON.stringify(data.decode)} 11 `); 12 } 13}, { 14 validation: function (data, callback) { 15 16 this.data = data; 17 this.callback = callback; 18 19 this.trig = () => { 20 21 //pass info from second param 22 callback(data, { 23 id: 1, 24 name: "Mosh" 25 }); 26 } 27 } 28});
1http.start(3000, function (route, method) { 2 return (data, callback) => { 3 callback(`Hello World`); 4 } 5}, { 6 public: 'assets', //public folder for js, css etc - this will load files automatically without routes 7 maxFileSize: 500 * 1024 * 1024, //allowed file size is set to 500 MB 8 onresponse: (resp, status) => { 9 //event triggered for each response sent 10 console.log("resp", resp); //the response value 11 console.log("status", status); //the response status code 12 }, 13 userBuffer: true, //use buffer (default: false) 14 contentTpe: http.CONTENT_TYPE.JSON //set content type (default: text/html) 15}); 16 17
1http.STATUS = { 2 OK: 200, 3 NO_CONTENT: 204, 4 REDIRECT_URI: 308, 5 BAD_REQUEST: 400, 6 UNAUTHORIZED: 401, 7 FORBIDDEN: 403, 8 NOT_FOUND: 404, 9 CONFLICT: 409, 10 TOO_MANY: 429 11};
1http.CONTENT_TYPE = { 2 HTML: 'html', 3 CSS: 'css', 4 JS: 'js', 5 ICO: 'ico', 6 JPEG: 'jpg', 7 PNG: 'png', 8 WOFF2: 'woff2', 9 WOFF: 'woff', 10 TTF: 'ttf', 11 EOT: 'eot', 12 SVG: 'svg', 13 JSON: 'json', 14 XLSX: 'xlsx' 15}
No vulnerabilities found.
No security vulnerabilities found.