{"id":49736,"url":"https://github.com/romuloalves/micro-post","last_synced_at":"2025-07-31T02:31:36.275Z","repository":{"id":236480872,"uuid":"792696477","full_name":"romuloalves/micro-post","owner":"romuloalves","description":"Package to only accept POST request for microservices built with zeit/micro","archived":false,"fork":false,"pushed_at":"2024-04-27T10:03:17.000Z","size":270,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-26T14:41:29.574Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/romuloalves.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,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-04-27T10:03:07.000Z","updated_at":"2024-04-27T10:03:24.000Z","dependencies_parsed_at":"2024-04-27T10:40:39.837Z","dependency_job_id":"5e780a41-0597-4c06-99ab-749e6a6db480","html_url":"https://github.com/romuloalves/micro-post","commit_stats":null,"previous_names":["romuloalves/micro-post"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/romuloalves/micro-post","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/romuloalves%2Fmicro-post","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/romuloalves%2Fmicro-post/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/romuloalves%2Fmicro-post/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/romuloalves%2Fmicro-post/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/romuloalves","download_url":"https://codeload.github.com/romuloalves/micro-post/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/romuloalves%2Fmicro-post/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267977963,"owners_count":24175237,"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-07-31T02:00:08.723Z","response_time":66,"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":"2024-01-05T21:38:13.358Z","updated_at":"2025-07-31T02:31:35.980Z","avatar_url":"https://github.com/romuloalves.png","language":"TypeScript","funding_links":[],"categories":["Modules"],"sub_categories":["HTTP Requests"],"readme":"# micro-post\n\n\u003e Package to only accept POST request for microservices built with [Micro](https://github.com/zeit/micro).\n\n[![XO code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/sindresorhus/xo)\n\n## About\n\nWhen developing a microservice with Nodejs and [zeit](https://github.com/zeit)/[micro](https://github.com/zeit/micro) you may want to accept only POST methods.\n`micro-post` is a simple package that allows you to achieve this with a lot of simplicity.\n\nJust encapsulating your existing function in the `micro-post` default exported function will automatically validate the requests, include the `Access-Control-Request-Method` and status code in the response header, and response body with `Method Not Allowed`.\n\nThe package allows you to modify it's response code, plain text, change the response by a JSON or even execute a function to manage the request by your own. You can find how to do that in the examples section.\n\n\n## Installation\n\nInstall using [npm](https://www.npmjs.com/):\n```\nnpm install --save micro-post\n```\n\nInstall using [yarn](https://yarnpkg.com/en/):\n```\nyarn add micro-post\n```\n\n## Usage\n\n### Basic\n\nThis is the basic usage. When a non-POST request is received, the response will be `405 – Method Not Allowed`.\n\n```js\nconst post = require('micro-post')\n\nmodule.exports = post(async (req, res) =\u003e {\n  return `It's a POST request!`\n})\n```\n\n### With options\n\nYou can parameterize some different responses like other messages, JSON and even a function to manage the request by your own.\n\n```js\nconst post = require('micro-post')\n\nconst options = {\n  errorCode: 404,\n  response: 'My custom response',\n  contentType: 'text/plain'\n}\n\nmodule.exports = post(options, async (req, res) =\u003e {\n  return `It's a POST request!`\n})\n```\n\n## Examples\n\n*Each example has its own README explaining how to execute it.*\n\n### All default options: \u003ca href=\"./example/default\"\u003edefault\u003c/a\u003e\n\nExample that use the default options of the package.\n\n\n\n### Custom Message: \u003ca href=\"./examples/custom-message\"\u003ecustom-message\u003c/a\u003e\n\nThe response is a custom message `Changing the default message is simple as breathe` with content-type `text/plain`.\n\n\n\n### Custom JSON: \u003ca href=\"./example/custom-json\"\u003ecustom-json\u003c/a\u003e\n\nThe response is a custom JSON  with content-type `application/json`.\n\n\n*The package change automatically the content-type to `application/json` in case your `response` property in the options parameter is an object.*\n\n```js\n{\n  error: {\n    message: 'Invalid method'\n  }\n}\n```\n\n\n### Custom HTML: \u003ca href=\"./example/custom-html\"\u003ecustom-html\u003c/a\u003e\n\nThe response is a custom HTML  with content-type `text/html`.\n\n\n\n### Custom Function: \u003ca href=\"./example/custom-function\"\u003ecustom-function\u003c/a\u003e\n\nBefore the response ends, the function that receives the `request` and the `response` from HTTP is called.\n\n\n\n## Developing/Contributing\n\n*Feel free to open issues and create PRs! :)*\n\nThis package is linted by [XO](https://github.com/sindresorhus/xo) and tested by [AVA](https://github.com/avajs/ava).\n\nAfter install the dependencies you can execute `npm test`, that will test different responses. Each test creates its [Micro](https://github.com/zeit/micro) instance to simulate a real environment.\n\n\n## License\n\nMIT License\n\nCopyright (c) 2016 Rômulo Alves\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fromuloalves%2Fmicro-post","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fromuloalves%2Fmicro-post","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fromuloalves%2Fmicro-post/lists"}