{"id":20716562,"url":"https://github.com/akira-cn/http-modular","last_synced_at":"2025-04-23T13:21:55.216Z","repository":{"id":187427066,"uuid":"676868904","full_name":"akira-cn/http-modular","owner":"akira-cn","description":"A universal library for converting server-side functions into ES Modules.","archived":false,"fork":false,"pushed_at":"2023-08-13T01:32:48.000Z","size":74,"stargazers_count":148,"open_issues_count":1,"forks_count":7,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-03-30T00:04:13.877Z","etag":null,"topics":["bff","esmodules","http-server","javascript","nodejs","rpc","rpc-library"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/akira-cn.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,"governance":null}},"created_at":"2023-08-10T07:43:20.000Z","updated_at":"2025-01-27T09:01:42.000Z","dependencies_parsed_at":"2023-08-10T11:04:34.125Z","dependency_job_id":"90c4f2d5-1067-4616-9f48-8843f8dd6bbe","html_url":"https://github.com/akira-cn/http-modular","commit_stats":null,"previous_names":["akira-cn/es-modular"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akira-cn%2Fhttp-modular","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akira-cn%2Fhttp-modular/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akira-cn%2Fhttp-modular/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akira-cn%2Fhttp-modular/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/akira-cn","download_url":"https://codeload.github.com/akira-cn/http-modular/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250439458,"owners_count":21430853,"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":["bff","esmodules","http-server","javascript","nodejs","rpc","rpc-library"],"created_at":"2024-11-17T03:06:04.243Z","updated_at":"2025-04-23T13:21:55.168Z","avatar_url":"https://github.com/akira-cn.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# HTTP-Modular\n\nA universal library for converting server-side functions into ES Modules.\n\n\u003cimg src=\"https://aircode-yvo.b-cdn.net/resource/modules-9sfv4swzvco.svg\" width=\"200\"\u003e\n\n**HTTP-Modular is a compact RPC library that unlocks the full potential of BFF (Back end for FrontEnd) capabilities.**\n\nGone are the days of cumbersome code like this:\n\n```js\n// server-side\napp.post('/save', async (context) =\u003e {\n  ......\n  const data = await getData(context);\n  const result = await db.save(data);\n  context.body = result;\n});\n```\n\n```js\n// in browser\n...\nconst res = await fetch('https://\u003cserver.url\u003e:\u003cport\u003e/save', {\n  method: 'POST',\n  body: JSON.stringify(data),\n  headers: {\n    ...\n  }\n);\nconst result = await res.json();\n...\n```\n\nEmbrace the future of coding with modular capabilities:\n\n```js\n// server-side\n...\nasync function save(data) {\n  ......\n  return await db.save(data);\n}\napp.all('/action', modular({save, list, delete}, config.koa));\n```\n\n```js\n// in browser\nimport {save, list, delete} from 'https://\u003cserver.url\u003e:\u003cport\u003e/action';\n...\nconst result = await save(data); // done!\n...\n```\n\n### Explore the Online Demo\n\nServer: Check out [the GitHub repository](https://github.com/AirCodeLabs/aircode/tree/main/examples/modular-demo\n)\n\nClient: Experiment with the library on [CodePen](https://codepen.io/akira-cn/pen/mdQYvmz)\n\n## Features\n\n- 🧸 Lightweight and user-friendly design.\n- 🌎 Compatible everywhere: Supports a wide range of Node.js HTTP servers and cloud environments.\n\n  HTTP-Modular seamlessly integrates with various environments using dedicated configurations for:\n  \n  - [x] [Koa](https://koajs.com/) - [Integrating with Koa](#1-integrating-with-koa)\n  - [x] [Express](https://expressjs.com/) - [Integrating with Express](#2-integrating-with-express)\n  - [x] [Fastify](https://fastify.dev/) - [Integrating with Fastify](#3-integrating-with-fastify)\n  - [x] [Nitro](https://nitro.unjs.io/) - [Integrating with Nitro](#4-integrating-with-nitro)\n  - [x] [Vercel](https://vercel.com/) - [Integrating with Vercel](#5-integrating-with-vercel-api-functions)\n  - [x] [AirCode](https://aircode.io/) - [Integrating with AirCode](#6-integrating-with-aircode-cloud-functions)\n\n- 🧩 Effortless extensibility.\n\n  Extend HTTP-Modular to other environments like Deno, Edge Runtime, or Ben by crafting custom configurations.\n\n## Quick Started\n\n### 1. Integrating with Koa:\n\n```js\nimport Koa from \"koa\";\nimport { bodyParser } from \"@koa/bodyparser\";\nimport { modular, context, config } from 'http-modular';\n\nfunction add(x, y) {\n  return x + y;\n}\n\nconst getHost = context(ctx =\u003e ctx.request.hostname);\n\nconst app = new Koa();\napp.use(bodyParser());\n\n// response\napp.use(modular({ add, getHost }, config.koa));\n\napp.listen(3000);\n```\n\n### 2. Integrating with Express:\n\n```js\nimport express from \"express\";\nimport bodyParser from 'body-parser';\nimport { modular, context, config } from 'http-modular';\n\nconst app = express();\n\napp.use(bodyParser.json({\n  limit: '4.5mb',\n  type: '*/*',\n}));\n\nfunction add(x, y) {\n  return x + y;\n}\n\nconst getHost = context(ctx =\u003e ctx.request.hostname);\n\nfunction getMessage() {\n  return {hi: 'there'};\n}\n\napp.all('/', modular({ add, getHost, getMessage }, config.express));\n\napp.listen(3000);\n```\n\n### 3. Integrating with Fastify:\n\n```js\nimport Fastify from 'fastify';\nimport { modular, context, config } from 'http-modular';\n\nconst fastify = Fastify({\n  logger: true\n});\n\n\nfunction add(x, y) {\n  return x + y;\n}\n\nconst getHost = context(ctx =\u003e ctx.request.hostname);\n\nfunction getMessage() {\n  return {hi: 'there'};\n}\n\n// Declare a route\nfastify.all('/', modular({add, getHost, getMessage}, config.fastify));\n\n// Run the server!\nfastify.listen({ port: 3000 }, function (err, address) {\n  if (err) {\n    fastify.log.error(err);\n    process.exit(1);\n  }\n  // Server is now listening on ${address}\n});\n```\n\n### 4. Integrating with Nitro\n\n```js\nimport { modular, context, config } from 'http-modular';\n\nfunction add(x, y) {\n  return x + y;\n}\n\nconst echo = context(async (ctx) =\u003e {\n  return await readBody(ctx);\n})\n\nfunction getMessage() {\n  return {hi: 'there'};\n}\n\nexport default eventHandler(\n  modular({add, echo, getMessage}, config.nitro)\n);\n```\n\n### 5. Integrating with Vercel API Functions:\n\n```js\nimport { modular, context, config } from 'http-modular';\n\nfunction add(x, y) {\n  return x + y;\n}\n\nconst echo = context(ctx =\u003e ctx.request.body);\n\nfunction getMessage() {\n  return {hi: 'there'};\n}\n\nexport default modular({add, echo, getMessage}, config.vercel);\n```\n\n### 6. Integrating with AirCode Cloud Functions:\n\n```js\nimport {config, context, modular} from 'http-modular';\n\nfunction add(x, y) {\n  return x + y;\n}\n\nconst getUrl = context(ctx =\u003e ctx.url);\n\nexport default modular({\n  add,\n  getUrl,\n}, config.aircode);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakira-cn%2Fhttp-modular","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fakira-cn%2Fhttp-modular","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakira-cn%2Fhttp-modular/lists"}