All Projects → http4ts → http4ts

http4ts / http4ts

Licence: MIT license
Server as a Function http toolkit for TypeScript & JavaScript

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language
CSS
56736 projects

Projects that are alternatives of or similar to http4ts

Http4k
The Functional toolkit for Kotlin HTTP applications. http4k provides a simple and uniform way to serve, consume, and test HTTP services.
Stars: ✭ 1,883 (+6176.67%)
Mutual labels:  http-client, http-server
Http4s
A minimal, idiomatic Scala interface for HTTP
Stars: ✭ 2,173 (+7143.33%)
Mutual labels:  http-client, http-server
Aiohttp
Asynchronous HTTP client/server framework for asyncio and Python
Stars: ✭ 11,972 (+39806.67%)
Mutual labels:  http-client, http-server
Zio Tls Http
100% non-blocking, Java NIO only( inspired by zio-nio) , JSON HTTP server based on Scala ZIO library. Everything including TLS encryption modeled as ZIO effects, convenient route DSL similar to https4s, up to 30K TPS local JSON transaction with 25 threads on 6 cores(i7) with ZIO fibers.
Stars: ✭ 71 (+136.67%)
Mutual labels:  http-client, http-server
cpphttpstack
c++ api for http client & server
Stars: ✭ 30 (+0%)
Mutual labels:  http-client, http-server
Qtnetworkng
QtNetwork Next Generation. A coroutine based network framework for Qt/C++, with more simpler API than boost::asio.
Stars: ✭ 125 (+316.67%)
Mutual labels:  http-client, http-server
Libhv
🔥 比libevent、libuv更易用的国产网络库。A c/c++ network library for developing TCP/UDP/SSL/HTTP/WebSocket client/server.
Stars: ✭ 3,355 (+11083.33%)
Mutual labels:  http-client, http-server
Jiny
Lightweight, modern, simple JVM web framework for rapid development in the API era
Stars: ✭ 40 (+33.33%)
Mutual labels:  http-client, http-server
Donkey
Modern Clojure HTTP server and client built for ease of use and performance
Stars: ✭ 199 (+563.33%)
Mutual labels:  http-client, http-server
Http Kit
http-kit is a minimalist, event-driven, high-performance Clojure HTTP server/client library with WebSocket and asynchronous support
Stars: ✭ 2,234 (+7346.67%)
Mutual labels:  http-client, http-server
Akka Http
The Streaming-first HTTP server/module of Akka
Stars: ✭ 1,163 (+3776.67%)
Mutual labels:  http-client, http-server
go-sse
Fully featured, spec-compliant HTML5 server-sent events library
Stars: ✭ 165 (+450%)
Mutual labels:  http-client, http-server
Flogo Contrib
Flogo Contribution repo. Contains activities, triggers, models and actions.
Stars: ✭ 60 (+100%)
Mutual labels:  http-client, http-server
Fs2 Http
Http Server and client using fs2
Stars: ✭ 132 (+340%)
Mutual labels:  http-client, http-server
Foxy
Session-based Beast/Asio wrapper requiring C++14
Stars: ✭ 57 (+90%)
Mutual labels:  http-client, http-server
Httpp
Micro http server and client written in C++
Stars: ✭ 144 (+380%)
Mutual labels:  http-client, http-server
Sylar
C++高性能分布式服务器框架,webserver,websocket server,自定义tcp_server(包含日志模块,配置模块,线程模块,协程模块,协程调度模块,io协程调度模块,hook模块,socket模块,bytearray序列化,http模块,TcpServer模块,Websocket模块,Https模块等, Smtp邮件模块, MySQL, SQLite3, ORM,Redis,Zookeeper)
Stars: ✭ 895 (+2883.33%)
Mutual labels:  http-client, http-server
Cxxhttp
Asynchronous, Header-only C++ HTTP-over-(TCP|UNIX Socket|STDIO) Library
Stars: ✭ 24 (-20%)
Mutual labels:  http-client, http-server
Zio Http
A scala library to write Http apps.
Stars: ✭ 162 (+440%)
Mutual labels:  http-client, http-server
EthernetWebServer SSL
Simple TLS/SSL Ethernet WebServer, HTTP Client and WebSocket Client library for for AVR, Portenta_H7, Teensy, SAM DUE, SAMD21, SAMD51, STM32F/L/H/G/WB/MP1, nRF52 and RASPBERRY_PI_PICO boards using Ethernet shields W5100, W5200, W5500, ENC28J60 or Teensy 4.1 NativeEthernet/QNEthernet. It now supports Ethernet TLS/SSL Client. The library supports …
Stars: ✭ 40 (+33.33%)
Mutual labels:  http-client, http-server

http4ts

Server as a Function HTTP toolkit for TypeScript

Node Deno codecov

http4ts is a minimal HTTP library for JavaScript environments (Node.js, Deno etc.) implementing the pattern of server as a function. In http4ts, a server is just a function with the following signature:

type HttpHandler = (req: HttpRequest) => HttpResponse | Promise<HttpResponse>;

See the simple server application examples, one for deno and another for Node.js.

Using in Node.js

Installation

Http4ts is available via npm. You can install it using the following command:

npm install http4ts

Binding to Node.js

In order to use this library in Node.js, you have to bind the HttpHandler to the Node.js HTTP server. Http4ts supplies a function called toNodeRequestListener to bind an HttpHandler to the server.

import * as http from "http";

import {
  HttpRequest,
  toNodeRequestListener,
  OK
} from "http4ts";

async function handler(req: HttpRequest) {  // 1. Write the handler as a function that returns response
  return OK({ body: "Hello world!" });
}

const server = http.createServer(
  toNodeRequestListener(handler)            // 2. Connect the handler to the node.js server
);

const hostname = "127.0.0.1";
const port = 3000;

server.listen(port, hostname, () => {       // 3. Start your node server as you were before
  console.log(`Server running at http://${hostname}:${port}/`);
});

Using in Deno

Installation

In Deno, it is possible to import the library via its url. You can use Http4ts by importing the following url:

https://deno.land/x/http4ts/mod.ts

Binding to Deno

In order to use this library in Deno, you have to bind the HttpHandler to the Deno HTTP server. Http4ts supplies a function called toDenoRequestListener to bind an HttpHandler to the server.

import { listenAndServe } from "https://deno.land/std/http/server.ts";

import {
  HttpRequest,
  toDenoRequestListener,
  OK
} from "https://deno.land/x/http4ts/mod.ts";

async function handler(req: HttpRequest) {  // 1. Write the handler as a function that returns response
  return OK({ body: "Hello world!" });
}

console.log("Listening on http://localhost:8000");
await listenAndServe({ port: 8000 }, toDenoRequestListener(handler));

You can also run this example by executing the following command in your shell environment:

deno run --allow-net=0.0.0.0:8000 https://deno.land/x/http4ts/examples/readme-example.ts

Philosophy

http4ts aims to obey the following rules as its base architectural mindset:

  • Server as a Function: This library is based on the Twitter paper Your Server as a Function and inspired by the fantastic http4k library. An HTTP server application is a composition of two main types:
    • HttpHandler: defines the functions that handle requests.
    • HttpFilter: a higher-order function that accepts an HttpHandler and returns an HttpHandler. It should be used to add request/response pre-/post-processing.
  • Runtime Independence: This library has bindings for both Node.js and Deno runtimes.
  • Symmetric: Similar to http4k, this library supports symmetric interfaces for the HTTP client and HTTP server. It is possible to reuse the same HttpHandler interface and all the filters on both server- and client-side. There is an HttpClient functionality available in the library which follows the fetch interface and is independent of any runtime.
  • Type Safety: http4ts is built using the maximum type safety power of TypeScript and, in order to use its maximum power, you should do the same.
  • Immutability: Similar to http4k, all entities in the library are immutable unless, naturally, it is not possible.
  • Testability: Since the basic building blocks of this library are functions and the main entities are abstracted from the environment, it is extremely simple to write tests for the code built by http4ts.
  • Minimal The request and response contain only the necessary information to represent the HTTP message. Extra information such as session and cookies are not included because they don't belong to the HTTP protocol.
  • Composable All the building blocks are composable which is a great addition to code reusability, organization and extension.

Http4ts data-flows

Https Data Flows

Example Project

We have implemented the famous realworld backend for you to compare the code with other http libraries in node.js. You can find this example here.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].