Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
A lightweight HTTP framework for Typescript / JS, with zero dependencies
NativeHttpServer
and HttpClient
stream in and out by default. A handle on
the stream is provided by req.bodyStream()
and a res
is streamed out if
a Res(200, BodyOf(readable))
is provided, i.e. a Readable
stream body.
We use ssl-root-cas
to trust self-signed certs for testing NativeHttpsServer
.
This has been moved from prod code to the test code. Needs releasing because
otherwise ssl-root-cas
needs to be a dependency.
Req
streamAs we provide this handle via req.bodyStream()
, accessing the form
on an
incoming Req
is now done via req.bodyForm()
in order to realise the stream.
req.bodyString()
will also realise it and work as expected.
In order to evolve the core library faster support for Express and Koa backends has been dropped. Happy to add back later.
combining routes using withRoutes
no longer combines filters from each routing.
See here for more info
npm install --save http4js
or
yarn add http4js
An example server and client
//define our routes
const routing = routes('GET', ".*", async (req: Req) => {
console.log(req);
return ResOf(Status.OK, 'OK');
})
//add csrf token header to every request and vary gzip to every response
const headerFilter = (handler: HttpHandler) => {
return async (req: Req) => {
const response = await handler(req.withHeader(Headers.X_CSRF_TOKEN, Math.random()))
return response.withHeader(Headers.VARY, "gzip");
}
};
routing
.withFilter(headerFilter)
.asServer() // starts on port 3000 by default
.start();
//make an http request to our server and log the response
HttpClient(ReqOf(Method.GET, "http://localhost:3000/any/path"))
// output
Req {
headers:
{ host: 'localhost:3000',
connection: 'close',
'content-type': 'application/x-www-form-urlencoded',
'x-csrf-token': 0.8369821184747923 },
queries: {},
pathParams: {},
form: {},
method: 'GET',
uri:
Uri {
matches: {},
asNativeNodeRequest:
Url {
...,
protocol: 'http:',
host: 'localhost:3000',
port: '3000',
pathname: '/any/path',
path: '/any/path',
href: 'http://localhost:3000/any/path' } },
body: '' }
I'd be very happy if you'd like to contribute :)
git clone git@github.com:TomShacham/http4js.git && \
cd http4js && \
yarn && \
yarn build && \
yarn test
http4js is a port of http4k.
The concept is called Server as a Function (SaaF).
Early ideas and influence from Daniel Bodart's Utterly Idle
We need our own certs to run an HTTPS server locally.
These Commands get you most of the way, I altered them slightly for this script, that may work for you
./create-ssl-certs.sh
If not, follow these Instructions to create your own certificates in order to run an HTTPS server locally.
Then run
yarn test-ssl
FAQs
A lightweight HTTP toolkit
The npm package http4js receives a total of 703 weekly downloads. As such, http4js popularity was classified as not popular.
We found that http4js demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers 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
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.