{"id":13747297,"url":"https://github.com/vergilet/repost","last_synced_at":"2025-04-05T06:10:05.835Z","repository":{"id":47096257,"uuid":"167270665","full_name":"vergilet/repost","owner":"vergilet","description":"Redirect using POST method","archived":false,"fork":false,"pushed_at":"2024-02-25T10:20:18.000Z","size":66,"stargazers_count":85,"open_issues_count":1,"forks_count":12,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-29T05:09:36.435Z","etag":null,"topics":["html-form","post","rails","redirect","redirect-post","repost","ruby","sinatra"],"latest_commit_sha":null,"homepage":"https://vergilet.github.io/repost","language":"Ruby","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/vergilet.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","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":"2019-01-23T23:36:31.000Z","updated_at":"2025-01-14T12:03:49.000Z","dependencies_parsed_at":"2024-06-18T18:46:47.959Z","dependency_job_id":null,"html_url":"https://github.com/vergilet/repost","commit_stats":{"total_commits":69,"total_committers":9,"mean_commits":7.666666666666667,"dds":"0.30434782608695654","last_synced_commit":"d6723b622d2bbb6ce7b3d341e05efc63215c0454"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vergilet%2Frepost","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vergilet%2Frepost/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vergilet%2Frepost/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vergilet%2Frepost/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vergilet","download_url":"https://codeload.github.com/vergilet/repost/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247294541,"owners_count":20915340,"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":["html-form","post","rails","redirect","redirect-post","repost","ruby","sinatra"],"created_at":"2024-08-03T06:01:24.283Z","updated_at":"2025-04-05T06:10:05.807Z","avatar_url":"https://github.com/vergilet.png","language":"Ruby","funding_links":[],"categories":["Ruby"],"sub_categories":[],"readme":"\u003cp align=\"right\"\u003e\n    \u003ca href=\"https://github.com/vergilet/repost\"\u003e\u003cimg align=\"\" src=\"https://user-images.githubusercontent.com/2478436/51829223-cb05d600-22f5-11e9-9245-bc6e82dcf028.png\" width=\"56\" height=\"56\" /\u003e\u003c/a\u003e\n\u003ca href=\"https://rubygems.org/gems/repost\"\u003e\u003cimg align=\"right\" src=\"https://user-images.githubusercontent.com/2478436/51829691-c55cc000-22f6-11e9-99a5-42f88a8f2a55.png\" width=\"56\" height=\"56\" /\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://rubygems.org/gems/repost\"\u003e\n  \u003cimg width=\"460\" src=\"https://user-images.githubusercontent.com/2478436/55672583-44491880-58a5-11e9-945c-939f90470df8.png\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\nGem **Repost** implements Redirect using POST method.\n\nImplementation story and some details in the following article [Redirect using POST in Rails](https://medium.com/@momlookhowican/redirect-using-post-in-rails-5748da354343).\n\n[![Gem Version](https://badge.fury.io/rb/repost.svg)](https://badge.fury.io/rb/repost)\n[![Build Status](https://travis-ci.com/vergilet/repost.svg?branch=master)](https://app.travis-ci.com/github/vergilet/repost)\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'repost'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install repost\n\n\n\n## What problem does it solve?\n\nWhen you need to send some parameters to an endpoint which should redirect you after execution. There wouldn't be a problem if an endpoint receives [GET], because you can just use: \n```ruby\nredirect_to entity_url(id: @model.id, token: model.token...)\n```\n\n\nBut when an endpoint receives [POST], you have to generate html form and submit it. So `repost` gem helps to avoid creation of additional view with html form, just use `redirect_post` method instead.\nI faced with this problem when was dealing with bank transactions. You can see the approximate scheme:\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://user-images.githubusercontent.com/2478436/55143646-d0da3500-5147-11e9-91a3-1bac9d560fb2.png\"\u003e\n  \u003cimg src=\"https://user-images.githubusercontent.com/2478436/55143646-d0da3500-5147-11e9-91a3-1bac9d560fb2.png\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n\u003e **P.S. The `repost` gem was initially created in response to the redirection process required by [Adyen 3D Secure 1](https://docs.adyen.com/online-payments/classic-integrations/api-integration-ecommerce/3d-secure/3d-secure-1/#step-2-redirect-to-the-card-issuer), which often involved creating an HTML form and submitting it via POST. \u003cbr\u003e\nHowever, with the advent of 3D Secure 2, which aims for a more integrated authentication experience, the use of such forms for POST submissions has not been encountered. 3D Secure 2 typically manages authentication data exchanges in the background, potentially eliminating the need for manual form submission.**\n\n\n## Usage\n\nIf you use Rails, gem automatically includes helper methods to your controllers:\n\n```ruby\nrepost(...)\n```\nand, as an alias\n\n```ruby\nredirect_post(...)\n```\n\n*Under the hood it calls `render` method of current controller with `html:`.*\n\n### Example in Rails app:\n\n```ruby\nclass MyController \u003c ApplicationController\n  ...\n  def index\n    repost(...)\n  end\n  ...\n  # or\n  def show\n    redirect_post(...)\n  end\nend\n```\n______________\n\nIf you use Sinatra, Roda or etc., you need to require it first somewhere in you project:\n\n```ruby\nrequire 'repost'\n```\n\nThen ask senpai to generate a string with html:\n\n\n```ruby\nRepost::Senpai.perform(...)\n```\n\n### Example in Sinatra, Roda, etc. app:\n\n```ruby\nclass MyController \u003c Sinatra::Base\n  get '/' do\n    Repost::Senpai.perform(...)\n  end\nend\n```\n\n\n\n#### *Reminder:*\n\n- *In Rails app use `repost` or `redirect_post` method in your controller which performs 'redirect' when it is called.*\n\n- *In Sinatra, Roda, etc. app or if you need html output - call Senpai*\n\n\n#### Full example:\n\n*UPD: authenticity token is **turned off** by default. Use `:auto` or `'auto'` to turn on default authenticity token from Rails. Any other string value would be treated as custom auth token value.*\n\n```ruby\n# plain ruby\n# Repost::Senpai.perform('http://......)\n\n\n# Rails\nredirect_post('http://examp.io/endpoint',            # URL, looks understandable\n  params: {\n            a: 1,\n            'b': { \"c\": 2 },\n            d: [ 3, 4, 5 ],\n            e: { f: 'string', g: [ 6, 7, 8 ] }\n          },                                         # Your request body, also nested params and arrays\n  options: {\n    method: :post,                                   # OPTIONAL - DEFAULT is :post, but you can use others if needed\n    status: :ok,                                     # OPTIONAL - DEFAULT is :ok. This is the http status that the form will be returned with.\n    authenticity_token: 'auto',                      # OPTIONAL - :auto or 'auto' for Rails form_authenticity_token, string - custom token\n    charset: 'Windows-1251',                         # OPTIONAL - DEFAULT is \"UTF-8\", corresponds for accept-charset\n    form_id: 'CustomFormID',                         # OPTIONAL - DEFAULT is autogenerated\n    autosubmit: false,                               # OPTIONAL - DEFAULT is true, if you want to get a confirmation for redirect\n    autosubmit_nonce: '1d3n7i4ier',                  # RAILS - DEFAULT is content_security_policy_nonce, for pure Ruby - string identifier, more info - https://edgeguides.rubyonrails.org/security.html#content-security-policy\n    decor: {                                         # If autosubmit is turned off or Javascript is disabled on client\n      section: {                                     # ... you can decorate confirmation section and button\n        classes: 'red-bg red-text',                  # OPTIONAL - \u003cDIV\u003e section, set classNames, separate with space\n        html: '\u003ch1\u003ePress this button, dude!\u003c/h1\u003e'    # OPTIONAL - Any html, which will appear before submit button\n      },\n      submit: {\n        classes: 'button-decorated round-border',    # OPTIONAL - \u003cInput\u003e with type submit, set classNames, separate with space\n        text: 'c0n71nue ...'                         # OPTIONAL - DEFAULT is 'Continue'\n      }\n    }\n  }\n)\n\n```\n\n### Authenticity Token (Rails)\n\nCurrently you can pass the **authenticity token** in two ways:\n\n* Recommended:\n\n    *Use `options` and `:auto` to pass the auth token. That should protect you from any implementation changes in future Rails versions*\n\n    ```ruby\n    redirect_post('https://exmaple.io/endpoint', options: {authenticity_token: :auto})\n    ```\n* Or, it is still valid to:\n\n    *use `params` and `form_authenticity_token` method directly from ActionController*\n    ```ruby\n    redirect_post('https://exmaple.io/endpoint', params: {authenticity_token: form_authenticity_token})\n    ```\n\n\n\n## License\nThe gem is available as open source under the terms of the MIT License.\n\nCopyright © 2019 Yaro.\n\n[![GitHub license](https://img.shields.io/badge/license-MIT-brightgreen)](https://raw.githubusercontent.com/vergilet/repost/master/LICENSE.txt)\n\n**That's all folks.**\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvergilet%2Frepost","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvergilet%2Frepost","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvergilet%2Frepost/lists"}