{"id":17998392,"url":"https://github.com/primaryobjects/easypost","last_synced_at":"2025-06-19T07:11:14.780Z","repository":{"id":139343237,"uuid":"6616842","full_name":"primaryobjects/easypost","owner":"primaryobjects","description":"Example of reading POST data in node.js from both a form submission and from a REST client, using a manager method to abstract res.on('data') and res.on('end').","archived":false,"fork":false,"pushed_at":"2012-11-12T17:40:31.000Z","size":156,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-04T06:42:55.040Z","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/primaryobjects.png","metadata":{"files":{"readme":"README.txt","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":"2012-11-09T17:00:44.000Z","updated_at":"2016-05-04T09:43:11.000Z","dependencies_parsed_at":"2023-05-22T22:58:31.336Z","dependency_job_id":null,"html_url":"https://github.com/primaryobjects/easypost","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/primaryobjects/easypost","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/primaryobjects%2Feasypost","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/primaryobjects%2Feasypost/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/primaryobjects%2Feasypost/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/primaryobjects%2Feasypost/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/primaryobjects","download_url":"https://codeload.github.com/primaryobjects/easypost/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/primaryobjects%2Feasypost/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260705892,"owners_count":23049494,"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":"2024-10-29T21:25:06.433Z","updated_at":"2025-06-19T07:11:09.764Z","avatar_url":"https://github.com/primaryobjects.png","language":"JavaScript","readme":"EasyPost\n\nAn example of reading POST data in node.js. View the full tutorial at http://www.primaryobjects.com/CMS/Article144.aspx\n\nThis example shows how to read POST data from both a form submission, and a REST client. The code example uses a manager method. This helps abstract the extra work of using res.on('data') and res.on('end'). It also provides a single location for maintaing the code that reads POST data, allowing you to enhance it, such as with checks for flooding attacks, etc.\n\nWe'll cover reading data from a form submissions and reading data submitted through a REST client (ie., streamed).\n\nDemo @ http://easypost.herokuapp.com\n \nReading POST Data From a Form\n\n    CommonManager.getPostData(req, res, function (data) {\n        res.render('index', { txtName: data.txtName });\n    });\n\nReading POST Data From a REST Client\n\n    CommonManager.getPostData(req, res, function (data) {\n        data = JSON.parse(data);\n        res.render('index', { txtName: data.txtName });\n    });\n\nThe core manager method for reading the POST data is located in commonManager.js:\n\nCommonManager = {\n    getPostData: function (req, res, callback) {\n        // Check if this is a form post or a stream post via REST client.\n        if (req.readable) {\n            // REST post.\n            var content = '';\n\n            req.on('data', function (data) {\n                if (content.length \u003e 1e6) {\n                    // Flood attack or faulty client, nuke request.\n                    res.json({ error: 'Request entity too large.' }, 413);\n                }\n\n                // Append data.\n                content += data;\n            });\n\n            req.on('end', function () {\n                // Return the posted data.\n                callback(content);\n            });\n        }\n        else {\n            // Form post.\n            callback(req.body);\n        }\n    }\n}\n\nKory Becker\nhttp://www.primaryobjects.com\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprimaryobjects%2Feasypost","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprimaryobjects%2Feasypost","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprimaryobjects%2Feasypost/lists"}