{"id":23118539,"url":"https://github.com/http4ts/http4ts","last_synced_at":"2025-08-16T23:31:36.056Z","repository":{"id":35846312,"uuid":"189275247","full_name":"http4ts/http4ts","owner":"http4ts","description":"Server as a Function http toolkit for TypeScript \u0026 JavaScript","archived":false,"fork":false,"pushed_at":"2023-01-07T07:24:32.000Z","size":4793,"stargazers_count":34,"open_issues_count":36,"forks_count":2,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-08-09T08:19:51.066Z","etag":null,"topics":["deno","http","http-client","http-server","javascript","nodejs","typescript"],"latest_commit_sha":null,"homepage":"https://http4ts.js.org","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/http4ts.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-05-29T18:06:55.000Z","updated_at":"2024-12-07T07:30:29.000Z","dependencies_parsed_at":"2023-01-16T07:32:01.628Z","dependency_job_id":null,"html_url":"https://github.com/http4ts/http4ts","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/http4ts/http4ts","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/http4ts%2Fhttp4ts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/http4ts%2Fhttp4ts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/http4ts%2Fhttp4ts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/http4ts%2Fhttp4ts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/http4ts","download_url":"https://codeload.github.com/http4ts/http4ts/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/http4ts%2Fhttp4ts/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269723018,"owners_count":24464783,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-10T02:00:08.965Z","response_time":71,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["deno","http","http-client","http-server","javascript","nodejs","typescript"],"created_at":"2024-12-17T05:18:13.389Z","updated_at":"2025-08-16T23:31:35.480Z","avatar_url":"https://github.com/http4ts.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# http4ts\n\n**Server as a Function HTTP toolkit for TypeScript**\n\n[![Node](https://github.com/http4ts/http4ts/workflows/Node/badge.svg)](https://github.com/http4ts/http4ts/actions?query=workflow%3ANode)\n[![Deno](https://github.com/http4ts/http4ts/workflows/Deno/badge.svg)](https://github.com/http4ts/http4ts/actions?query=workflow%3ADeno)\n[![codecov](https://codecov.io/gh/http4ts/http4ts/branch/master/graph/badge.svg)](https://codecov.io/gh/http4ts/http4ts)\n\nhttp4ts is a minimal HTTP library for JavaScript environments ([Node.js](https://nodejs.org), [Deno](https://Deno.land/) etc.) implementing the pattern of server as a function. In http4ts, a server is just a function with the following signature:\n\n```ts\ntype HttpHandler = (req: HttpRequest) =\u003e HttpResponse | Promise\u003cHttpResponse\u003e;\n```\n\nSee the simple server application examples, one for [deno](https://github.com/http4ts/http4ts/tree/master/src/deno/examples) and another for [Node.js](https://github.com/http4ts/http4ts/tree/master/src/node/examples).\n\n## Using in Node.js\n\n### Installation\n\n_Http4ts_ is available via npm. You can install it using the following command:\n\n```\nnpm install http4ts\n```\n\n### Binding to Node.js\n\nIn 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`](https://github.com/http4ts/http4ts/blob/master/src/node/server.ts) to bind an `HttpHandler` to the server.\n\n```ts\nimport * as http from \"http\";\n\nimport {\n  HttpRequest,\n  toNodeRequestListener,\n  OK\n} from \"http4ts\";\n\nasync function handler(req: HttpRequest) {  // 1. Write the handler as a function that returns response\n  return OK({ body: \"Hello world!\" });\n}\n\nconst server = http.createServer(\n  toNodeRequestListener(handler)            // 2. Connect the handler to the node.js server\n);\n\nconst hostname = \"127.0.0.1\";\nconst port = 3000;\n\nserver.listen(port, hostname, () =\u003e {       // 3. Start your node server as you were before\n  console.log(`Server running at http://${hostname}:${port}/`);\n});\n```\n\n## Using in Deno\n\n### Installation\n\nIn Deno, it is possible to import the library via its url. You can use _Http4ts_ by importing the following url:\n\n```\nhttps://deno.land/x/http4ts/mod.ts\n```\n\n### Binding to Deno\n\nIn order to use this library in Deno, you have to bind the `HttpHandler` to the Deno HTTP server. _Http4ts_ supplies a function called [`toDenoRequestListener`](https://github.com/http4ts/http4ts/blob/master/src/deno/server.ts) to bind an `HttpHandler` to the server.\n\n```ts\nimport { listenAndServe } from \"https://deno.land/std/http/server.ts\";\n\nimport {\n  HttpRequest,\n  toDenoRequestListener,\n  OK\n} from \"https://deno.land/x/http4ts/mod.ts\";\n\nasync function handler(req: HttpRequest) {  // 1. Write the handler as a function that returns response\n  return OK({ body: \"Hello world!\" });\n}\n\nconsole.log(\"Listening on http://localhost:8000\");\nawait listenAndServe({ port: 8000 }, toDenoRequestListener(handler));\n```\n\nYou can also run this example by executing the following command in your shell environment:\n\n```\ndeno run --allow-net=0.0.0.0:8000 https://deno.land/x/http4ts/examples/readme-example.ts\n```\n\n## Philosophy\n\nhttp4ts aims to obey the following rules as its base architectural mindset:\n\n- **Server as a Function**: This library is based on the Twitter paper [Your Server as a Function](https://monkey.org/~marius/funsrv.pdf) and inspired by the fantastic [http4k](https://github.com/http4k/http4k/) library. An HTTP server application is a composition of two main types:\n  - `HttpHandler`: defines the functions that handle requests.\n  - `HttpFilter`: a higher-order function that accepts an `HttpHandler` and returns an `HttpHandler`. It should be used to add request/response pre-/post-processing.\n- **Runtime Independence**: This library has bindings for both [Node.js](https://nodejs.org/) and [Deno](https://deno.land/) runtimes.\n- **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`](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) interface and is independent of any runtime.\n- **Type Safety**: http4ts is built using the maximum type safety power of [TypeScript](https://www.typescriptlang.org/) and, in order to use its maximum power, you should do the same.\n- **Immutability**: Similar to http4k, all entities in the library are immutable unless, naturally, it is not possible.\n- **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.\n- **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.\n- **Composable** All the building blocks are composable which is a great addition to code reusability, organization and extension.\n\n**_Http4ts data-flows_**\n\n![Https Data Flows](https://raw.githubusercontent.com/http4ts/http4ts/master/doc/asset/diagram.png)\n\n## Example Project\n\nWe have implemented the famous [realworld backend](https://github.com/gothinkster/realworld) for you to compare the code with other http libraries in node.js. You can find this example [here](https://github.com/http4ts/http4ts-realworld-example-app).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhttp4ts%2Fhttp4ts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhttp4ts%2Fhttp4ts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhttp4ts%2Fhttp4ts/lists"}