{"id":24882845,"url":"https://github.com/dobschal/javascript-proxy-fun","last_synced_at":"2025-10-06T12:12:29.036Z","repository":{"id":124106167,"uuid":"595988118","full_name":"dobschal/javascript-proxy-fun","owner":"dobschal","description":"An example on how to use the JavaScript Proxy class.","archived":false,"fork":false,"pushed_at":"2023-02-01T10:44:00.000Z","size":985,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-02T14:56:03.510Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/dobschal.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-02-01T08:20:18.000Z","updated_at":"2023-02-01T08:20:59.000Z","dependencies_parsed_at":null,"dependency_job_id":"32b5dc3b-f8e1-4693-bd32-1236df1e9209","html_url":"https://github.com/dobschal/javascript-proxy-fun","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/dobschal/javascript-proxy-fun","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dobschal%2Fjavascript-proxy-fun","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dobschal%2Fjavascript-proxy-fun/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dobschal%2Fjavascript-proxy-fun/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dobschal%2Fjavascript-proxy-fun/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dobschal","download_url":"https://codeload.github.com/dobschal/javascript-proxy-fun/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dobschal%2Fjavascript-proxy-fun/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278607291,"owners_count":26014779,"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-10-06T02:00:05.630Z","response_time":65,"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":[],"created_at":"2025-02-01T13:16:34.525Z","updated_at":"2025-10-06T12:12:29.028Z","avatar_url":"https://github.com/dobschal.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Fun with JavaScript Proxy\n\nExample implementation on how to use the JavaScript Proxy class.\n\nTake a look into the `client/serverProxy.js` file:\n\n```javascript\nimport { postData } from \"./http.js\";\n\nexport const server = new Proxy({}, {\n    get(_, key) {\n        return async (data) =\u003e {\n            return await postData(`/${key}`, data);\n        };\n    }\n});\n```\n\nInstead of making a HTTP request to the server directly, we put a Proxy instance in between. This instance maps all method call to HTTP requests. \n\nOn the server side we map all request controllers, so that we can easily call them from the client side:\n```javascript\nconst api = require(\"./api.js\");\nconst app = express();\n\nObject.keys(api).forEach(methodName =\u003e {\n    app.post(`/${methodName}`, api[methodName]);\n});\n```\n\nThe result looks like:\n```javascript\n// client.js loaded inot index.html\nlet username = \"Aurelia\";\nawait server.saveUsername(username);\n\n// server.js (e.g. NodeJS)\nconst api = {\n    saveUsername(req, res) {\n        // ...update username from req.body in database\n        res.send({\n            message: `Updated username '${req.body}'.`\n        });\n    }\n};\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdobschal%2Fjavascript-proxy-fun","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdobschal%2Fjavascript-proxy-fun","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdobschal%2Fjavascript-proxy-fun/lists"}