{"id":25933364,"url":"https://github.com/robertwhurst/theta","last_synced_at":"2025-03-04T00:53:32.701Z","repository":{"id":40294286,"uuid":"154787484","full_name":"RobertWHurst/Theta","owner":"RobertWHurst","description":"ϴ - Realtime API Framework for Node.js","archived":false,"fork":false,"pushed_at":"2023-10-18T09:10:58.000Z","size":1034,"stargazers_count":7,"open_issues_count":3,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-05-01T18:34:36.164Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/RobertWHurst.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":["RobertWHurst"]}},"created_at":"2018-10-26T06:28:21.000Z","updated_at":"2023-05-06T23:48:39.000Z","dependencies_parsed_at":"2023-01-17T18:46:01.507Z","dependency_job_id":null,"html_url":"https://github.com/RobertWHurst/Theta","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobertWHurst%2FTheta","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobertWHurst%2FTheta/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobertWHurst%2FTheta/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobertWHurst%2FTheta/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RobertWHurst","download_url":"https://codeload.github.com/RobertWHurst/Theta/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241763726,"owners_count":20016162,"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":[],"created_at":"2025-03-04T00:53:32.161Z","updated_at":"2025-03-04T00:53:32.693Z","avatar_url":"https://github.com/RobertWHurst.png","language":"TypeScript","funding_links":["https://github.com/sponsors/RobertWHurst"],"categories":[],"sub_categories":[],"readme":"\r\n\u003cp align=\"center\"\u003e\u003cimg alt=\"ϴ\" src=\"http://i.imgur.com/GYry72P.png\"\u003e\u003c/p\u003e\r\n\u003cp align=\"center\"\u003e\r\n  \u003cimg src=\"https://github.com/RobertWHurst/Theta/workflows/Tests%20CI/badge.svg\"\u003e\r\n\u003c/p\u003e\r\n\r\nϴ (Theta) is a realtime server framework inspired by Koa and Express.\r\n\r\nIt allows users to build robust and well structured APIs over sockets rather\r\nthan HTTP, with the goal of enabling a new class of real time applications.\r\nTheta support a range of transports including both TCP and WebSocket.\r\n\r\n**Note: Better documentation is in the works. The project is very much in development.**\r\n\r\n## Installation\r\n\r\nInstall via NPM or Yarn\r\n\r\nFor the server: \r\n\r\n```sh\r\nyarn add @thetaapp/server\r\nyarn add @thetaapp/server-transport-web-socket\r\n```\r\nor \r\n```sh\r\nnpm install @thetaapp/server --save\r\nnpm install @thetaapp/server-transport-web-socket --save\r\n```\r\n\r\nFor the client: \r\n\r\n```sh\r\nyarn add @thetaapp/client\r\nyarn add @thetaapp/client-transport-web-socket\r\n```\r\nor \r\n```sh\r\nnpm install @thetaapp/client --save\r\nnpm install @thetaapp/client-transport-web-socket --save\r\n```\r\n\r\n## Getting Started\r\n\r\nCreating a server is easy and similar to express or koa.\r\n\r\n```js\r\n// SERVER SIDE\r\nconst { theta } = require('@thetaapp/server')\r\nconst { webSocketTransport } = require('@thetaapp/server-transport-web-socket')\r\n\r\nconst server = theta()\r\nserver.transport(webSocketTransport({ port: 3000 }))\r\n\r\nserver.handle('/greet/:name', (ctx) =\u003e {\r\n  ctx.send({ greeting: `Hello ${ctx.params.name}` })\r\n})\r\n\r\nserver.listen()\r\n```\r\n\r\nTo interact with our new server lets create a theta client\r\n```js\r\n// CLIENT SIDE\r\nimport { theta } from 'https://cdn.jsdelivr.net/npm/@thetaapp/client'\r\nimport { webSocketTransport } from 'https://cdn.jsdelivr.net/npm/@thetaapp/client-transport-web-socket'\r\n\r\nconst client = theta()\r\nclient.transport(webSocketTransport({ url: 'ws://localhost:3000' }))\r\n\r\nclient.connect()\r\n\r\nclient.send('/greet/Robert')\r\n\r\nclient.handle((data) =\u003e {\r\n  console.log(data)\r\n})\r\n```\r\n\r\nWe should see the following in the console\r\n\r\n```\r\n{ \"status\": \"ok\", \"greeting\": \"Hello Robert\" }\r\n```\r\n\r\n# Going Beyond the Request Response Cycle\r\n\r\nWeb sockets enable us to have a proper back and forth with our client and server,\r\nbeyond what the HTTP request response cycle offers us. With theta it's possible\r\nto have several messages passed and received in the same handler. In the\r\nfollowing example we will tweak our greet handler to fetch the name value\r\nafter the first message.\r\n\r\n```js\r\n// SERVER SIDE\r\nconst { theta } = require('@thetaapp/server')\r\nconst { webSocketTransport } = require('@thetaapp/server-transport-web-socket')\r\n\r\nconst server = theta()\r\nserver.transport(webSocketTransport({ port: 3000 }))\r\n\r\nserver.handle('/greet', async (ctx) =\u003e {\r\n\r\n  ctx = await ctx.request({ message: 'What is your name?' })\r\n\r\n  ctx.send({ message: `Hello ${ctx.data.name}` })\r\n})\r\n\r\napp.listen()\r\n```\r\n\r\nIn this example we handle a client asking for a greeting. We then as the client\r\nwhat is their name, after which we wait for the client to respond using the\r\nname path. We then use our new context data to send the client our new greeting.\r\n\r\nThis could be a problem if the client never responds, but Theta handles this\r\nwith a timeout. If the timeout elapses the handle method on the context will\r\nreject with a timeout error. We could catch this error, or allow it to propagate\r\nto theta's router. If this happens an error handler will be invoked.\r\n\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobertwhurst%2Ftheta","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frobertwhurst%2Ftheta","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobertwhurst%2Ftheta/lists"}