
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Kaph is loose-coupled set of tools for handle requests under node.js. It's not framework.
*In the Phoenician alphabet letter "kaph" indicates palm.
Design of kaph was inspired by Connect, Tornado and many others. But unlike them, it was designed to make all components as independent from each other without large overhead.
You can install kaph as usual - by copy "kaph" directory in your
~/.node_libraries
or via npm
npm install kaph
To handle request Kaph executes chain of defined operations.
var http = require('http');
var HttpHandler = require('kaph/http').Handler;
// Make some operations
OpA = {
DEFAULT: function() {
this.response.writeHead(200,
{'Content-Type': "text/html; charset=UTF-8"});
this.next();
}
};
OpB = {
GET: function(arg) {
this.response.end('OpB ' + arg);
},
ERROR: function(code, message) {
return code + ' ' + message;
}
};
var chain = [OpA, OpB]; // Our chain
var arg = ['Some arg']; // Optional arguments
http.createServer(function(request, response) {
// Just make new kaph handler and call the method "next"
(new HttpHandler(request, response, chain, arg)).next();
}).listen(9080);
Kaph handler receives four arguments:
request
is standart node.js http.ServerRequest
response
is standart node.js http.ServerResponse
chain
Array
of operations.args
Optional Array
of arguments.request
and response
may not be instances of node.js http
module. They
simply must have the same behavior. Handler never interfere with their
implementation. It use only request.method
property to choose operation
method (see below) as well as response
's writeHead
and end
methods
on exceptions.
Now about chain
. It's just Array
of Objects
. On each iteration kaph
handler invokes operation methods by following these rules:
request.method
, it performed as
a native method of handler (yes apply
) with optional arguments.DEFAULT
.To invoke next operation in chain you must call next
method of handler.
Kaph trying to handle all throwed exceptions without crash entire server. On
exception kaph handler ends request, logs error and try to send it to client.
To give a better description of exception you can throw new kaph.HandlerError
with two arguments: status code
and optional message
. Another way to throw
exception is handler's error
method with same arguments.
By default kaph handler generates client error message with own kaph.ERROR
function. You can replace it with method ERROR
of operation. ERROR
method
also takes two code
and message
arguments and returns String
.
Because handler performs the methods of operations as own, it's implementation is important. Each instance has next properties:
request
... well, you understand :)response
... well, it is also clear :)logger
is just node.js console
.As stated in the beginning, kaph is not framework. But in directory chain
you find a few things that can make life much more pleasant:
Each of them can be used independently of kaph. And of course kaph, not depend on them.
I'm use my own daleth
FAQs
Loose-coupled set of tools for handle requests under node.js
The npm package kaph receives a total of 4 weekly downloads. As such, kaph popularity was classified as not popular.
We found that kaph demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.