{"id":13821922,"url":"https://github.com/rumkin/plant","last_synced_at":"2025-07-27T04:31:34.890Z","repository":{"id":22393455,"uuid":"95485486","full_name":"rumkin/plant","owner":"rumkin","description":"🌳 JS web server charged with WebAPI and neat HTTP2 support","archived":false,"fork":false,"pushed_at":"2023-01-03T20:16:02.000Z","size":1211,"stargazers_count":80,"open_issues_count":37,"forks_count":6,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-10-23T11:57:10.251Z","etag":null,"topics":["http","javascript","js","server"],"latest_commit_sha":null,"homepage":"https://npmjs.com/package/@plant/plant","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rumkin.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-06-26T20:14:13.000Z","updated_at":"2024-04-04T03:33:04.000Z","dependencies_parsed_at":"2023-01-13T21:59:36.551Z","dependency_job_id":null,"html_url":"https://github.com/rumkin/plant","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rumkin%2Fplant","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rumkin%2Fplant/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rumkin%2Fplant/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rumkin%2Fplant/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rumkin","download_url":"https://codeload.github.com/rumkin/plant/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227759971,"owners_count":17815626,"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","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":["http","javascript","js","server"],"created_at":"2024-08-04T08:01:34.032Z","updated_at":"2024-12-02T16:12:44.582Z","avatar_url":"https://github.com/rumkin.png","language":"JavaScript","readme":"\u003cp align=\"center\"\u003e\n  \u003cimg alt=\"Plant logo\" src=\"packages/plant/dev/cover.png\" width=\"300\"/\u003e\n\u003c/p\u003e\n\n# Plant\n\n[![npm](https://img.shields.io/npm/v/@plant/plant.svg?style=flat-square)](https://npmjs.com/package/@plant/plant)\n[![npm](https://img.shields.io/npm/dw/@plant/plant.svg?style=flat-square)](https://npmjs.com/package/@plant/plant)\n![](https://img.shields.io/badge/size-8KiB-blue.svg?style=flat-square)\n\n[NPM](https://npmjs.com/package/@plant/plant) ·\n[Source](packages/plant) · [Readme](packages/plant/readme.md)\n\nPlant is WebAPI standards based HTTP2 web server, created with\nmodular architecture and functional design in mind. Also it's pure and less coupled.\n\nPlant supports HTTP 1 and HTTP 2 protocols. But it's transport agnostic and can work right\nin the browser over WebSockets, WebRTC, or PostMessage.\n\n## Features\n\n- ☁️ Lightweight: only **8** KiB minified and gzipped.\n- ✨ Serverless ready: works even in browser.\n- 🛡 Security oriented: uses the most strict [Content Securiy Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP) (CSP) by default.\n- 📐 Standards based: uses WebAPI interfaces.\n- 🛳 Transport agnostic: no HTTP or platform coupling, ship requests via __everything__.\n\n---\n\n## Table of Contents\n\n* [Install](#install)\n* [Examples](#exmaples)\n* [Packages](#packages)\n* [Internal packages](#internal-packages)\n\n## Install\n\n```bash\n# Install plant web server\nnpm i @plant/plant\n# Install node HTTP2 transport\nnpm i @plant/http2\n```\n\n## Examples\n\n### Hello World\n\nHello world with HTTP2 as transport.\n\n\u003e ⚠️ Note that default CSP header value is `default-src localhost; form-action localhost`.\n\u003e This will prevent  web page from loading any external resource at all.\n\u003e Set minimal required CSP on your own. Read about [CSP](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP) on Mozilla Developer Network\n\n\n```javascript\n// Build request handler\nconst createServer = require('@plant/http2');\nconst Plant = require('@plant/plant');\n\nconst plant = new Plant();\nplant.use(({res}) =\u003e {\n  res.body = 'Hello, World!'\n})\n\ncreateServer(plant)\n.listen(8080)\n```\n\n### Router\n\nPlant's builtin router is extremely simple and works only with\nexact strings. But there is more powerful router package which brings named params and regular expressions into routing.\n\n```javascript\nconst Plant = require('@plant/plant');\nconst Router = require('@plant/router');\n\nconst plant = new Plant()\nconst router = new Router()\n\nrouter.get('/user/:name', async function({res, route}) {\n  res.body = `Hello, ${route.params.name}!`\n})\n\nplant.use('/api/v1/*', router)\n```\n\n### HTTP2 pushes\n\nHello world with HTTP2 as transport.\n\n```javascript\n// Build request handler\nconst createServer = require('@plant/http2');\nconst Plant = require('@plant/plant');\n\nconst plant = new Plant();\n\nplant.use('/script.js', ({res}) =\u003e {\n  res.headers.set('content-type', 'application/javascript')\n  res.body = 'console.log(\"Hello\")'\n})\n\nplant.use('/index.html', ({res, fetch}) =\u003e {\n  // Push '/script.js' URL to pushed resources.\n  // It will be requested before sending main response.\n  res.push('/script.js')\n  // ... or ...\n  // Push complete response from subrequest\n  res.push(\n    await fetch('/script.js')\n  )\n\n  res.body = '\u003chtml\u003e\u003cscript src=\"/script.js\"\u003e\u003c/script\u003e\u003c/html\u003e'\n})\n\ncreateServer(plant)\n.listen(8080)\n```\n\n\n## Packages\n\n### [Router](packages/router) `@plant/router`\n\n[NPM](https://npmjs.com/package/@plant/router) ·\n[Source](packages/router) · [Readme](packages/router/readme.md)\n\nPlant standalone router.\n\n## HTTP(S) Packages\n\n### [HTTP2](packages/http2) `@plant/http2`\n\n[NPM](https://npmjs.com/package/@plant/http2) ·\n[Source](packages/http2) · [Readme](packages/http2/readme.md)\n\nPlant adapter for native node.js http2 module server. It creates server\nlistener from Plant instance and `http2.createServer()` [options](https://nodejs.org/dist/latest-v11.x/docs/api/http2.html#http2_http2_createserver_options_onrequesthandler). It's\nusage is the same as https module.\n\n### [HTTPS2](packages/https2) `@plant/https2`\n\n[NPM](https://npmjs.com/package/@plant/https2) ·\n[Source](packages/https2) · [Readme](packages/https2/readme.md)\n\nPlant adapter for native node.js http2 module SSL server. It creates server\nlistener from Plant instance and `http2.createSecureServer()` [options](https://nodejs.org/dist/latest-v11.x/docs/api/http2.html#http2_http2_createsecureserver_options_onrequesthandler). It's\nusage is the same as https module.\n\n### [HTTP](packages/http) `@plant/http`\n\n[NPM](https://npmjs.com/package/@plant/http) ·\n[Source](packages/http) · [Readme](packages/http/readme.md)\n\nPlant adapter for native node.js http module. It creates server listener from plant instance.\n\n### [HTTPS](packages/https) `@plant/https`\n\n[NPM](https://npmjs.com/package/@plant/https) ·\n[Source](packages/https) · [Readme](packages/https/readme.md)\n\nPlant adapter for native node.js https module. It creates server listener from plant instance and https options.\n\n### [HTTP Adapter](packages/http-adapter) `@plant/http-adapter`\n\n[NPM](https://npmjs.com/package/@plant/http-adapter) ·\n[Source](packages/http-adapter) · [Readme](packages/http-adapter/readme.md)\n\nThis package is using to connect Plant and native Node's HTTP server. Modules http, https, http2, and https2 use it under the hood.\n\n## Electron Packages\n\n### [Electron](packages/electron-adapter) `@plant/electron`\n\n[NPM](https://npmjs.com/package/@plant/electron) ·\n[Source](packages/electron) · [Readme](packages/electron/readme.md)\n\nThis package is using to connect Plant and with current Electron instance protocols API.\nIt's using `electron-adapter` under the hood.\n\n### [Electron Adapter](packages/electron-adapter) `@plant/electron-adapter`\n\n[NPM](https://npmjs.com/package/@plant/electron-adapter) ·\n[Source](packages/electron-adapter) · [Readme](packages/electron-adapter/readme.md)\n\nThis package is using to connect Plant and with Electron protocols API.\n\n## Utility Packages\n\n### [Flow](packages/flow) `@plant/flow`\n\n[NPM](https://npmjs.com/package/@plant/flow) ·\n[Source](packages/flow) · [Readme](packages/flow/readme.md)\n\nThis is library for cascades. This is where contexts manage take place and requests pass from one handler to another.\n\n### [Node Stream Utils](packages/node-stream-utils) `@plant/node-stream-utils`\n\n[NPM](https://npmjs.com/package/@plant/node-stream-utils) ·\n[Source](packages/node-stream-utils) · [Readme](packages/node-stream-utils/readme.md)\n\nNode \u003c-\u003e WebAPI streams adapters. Useful for wrapping Node.js streams to work\nwith Plant.\n\n## Tests Packages\n\n### [Test HTTP Suite](packages/test-http) `@plant/test-http`\n\n[NPM](https://npmjs.com/package/@plant/test-http) ·\n[Source](packages/test-http) · [Readme](packages/test-http/readme.md)\n\nTiny package with tools for HTTP testing. It simplify server creation and request sending and receiving.\n\n## License\n\nMIT \u0026copy; [Rumkin](https://rumk.in)\n","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frumkin%2Fplant","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frumkin%2Fplant","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frumkin%2Fplant/lists"}