@whi/http

0.2.3 • Public • Published

HTTP Utilities

This module is intended to extend the built-in HTTP server and provide a user friendly HTTP client wrapper around node-fetch.

Server

Create a server that defaults to static assets but can be configured to return dynamic responses.

const http = require('@whi/http');

const http_server = new http.server();
const settings = { version: "1.0.0" };

http_server.serve_local_assets( "./public/", function ( req_path ) {
    if ( req_path === "/settings" ) {
        this.contentType("application/json");
        return JSON.stringify( settings );
    }
});

http_server.listen( 8080 );

Client

HTTP client using node-fetch.

const http = require('@whi/http');

const api = http.client.create(`http://localhost:8080`);
const resp = await api.get("/settings");

resp.version === "1.0.0";

/@whi/http/

    Package Sidebar

    Install

    npm i @whi/http

    Weekly Downloads

    1

    Version

    0.2.3

    License

    ISC

    Unpacked Size

    6.51 kB

    Total Files

    5

    Last publish

    Collaborators

    • brisebom