Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 617269
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:25:02+00:00 2026-05-13T18:25:02+00:00

Within my Rails application, I’d like to generate requests that behave identically to genuine

  • 0

Within my Rails application, I’d like to generate requests that behave identically to “genuine” HTTP requests.

For a somewhat contrived example, suppose I were creating a system that could batch incoming HTTP requests for later processing. The interface for it would be something like:

  1. Create a new batch resource via the usual CRUD methodology (POST, receive a location to the newly created resource).
  2. Update the batch resource by sending it URLs, HTTP methods, and data to be added to the collection of requests it’s supposed to later perform in bulk.
  3. “Process” the batch resource, wherein it would iterate over its collection of requests (each of which might be represented by a URL, HTTP method, and a set of data), and somehow tell Rails to process those requests in the same way as it would were they coming in as normal, “non-batched” requests.

It seems to me that there are two important pieces of work that need to happen to make this functional:

First, the incoming requests need to be somehow saved for later. This could be simply a case of saving various aspects of the incoming request, such as the path, method, data, headers, etc. that are already exposed as part of the incoming request object within a controller. It would be nice if there was a more “automatic” way of handling this–perhaps something more like object marshaling or serialization–but the brute force approach of recording individual parameters should work as well.

Second, the saved requests need to be able to be re-injected into the rails application at a later time, and go through the same process that a normal HTTP request goes through: routing, controllers, views, etc. I’d like to be able to capture the response in a string, much as the HTTP client would have seen it, and I’d also like to do this using Rails’ internal machinery rather than simply using an HTTP library to have the application literally make a new request to itself.

Thoughts?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T18:25:02+00:00Added an answer on May 13, 2026 at 6:25 pm

    Rack Middleware

    After doing a lot of investigation after I’d initially asked this question, I eventually experimented with and successfully implemented a solution using Rack Middleware.

    A Basic Methodology

    In the `call’ method of the middleware:

    1. Check to see if we’re making a request as a nested resource of a
      transaction object, or if it’s an otherwise ordinary request. If it’s
      ordinary, proceed as normal through the middleware by making a call to
      app.call(env), and return the status, headers, and response.

    2. Unless this is a transaction commit, record the “interesting” parts of the
      request’s env hash, and save them to the database as an “operation” associated
      with this transaction object.

    3. If this is a transaction commit, retrieve all of the relevant operations
      for this transaction. Either create a new request environment, or clone the
      existing one and populate it with the values saved for the operation. Also
      make a copy of the original request environment for later restoration, if
      control is meant to pass through the application normally post-commit.

    4. Feed the constructed environment into a call to app.call(env). Repeat for
      each operation.

    5. If the original request environment was preserved, restore it and make one
      final call to app.call(env), returning from the invocation of `call’ in the
      middleware the status, headers, and response from this final call to
      app.call(env).

    A Sample Application

    I’ve implemented an example implementation of the methodology I describe here, which I’ve made available on GitHub. It also contains an in-depth example describing how the implementation might look from an API perspective. Be warned: it’s quite rough, totally undocumented (with the exception of the README), and quite possibly in violation of Rails good coding practices. It can be obtained here:

    • http://github.com/mcwehner/transact-example

    A Plugin/Gem

    I’m also beginning work on a plugin or gem that will provide this sort of interface to any Rails application. It’s in its formative stages (in fact it’s completely devoid of code at the moment), and work on it will likely proceed slowly. Explore it as it develops here:

    • http://github.com/mcwehner/transact

    See also

    • Railscasts – Rack Middleware
    • Rails Guides – Rails on Rack
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd like to create a link in a view within a Rails application that
I'm using DRb within a Rails application to offload an expensive task outside the
Within Ruby on Rails applications database.yml is a plain text file that stores database
Rails noob here. I have a rails application with (in this example) three tables.
I am developing a web app (using rails) that I will be launching within
I'm writing an integration test for a rails application using Capybara within Rspec. After
I am working on a Rails application that has user authentication which provides an
Some functionality within my rails application looks better as if it was a separate
I'm using flickr-fu gem within a rails application for flickr api integration. I'm following
I'm trying to work with the data in my Rails application from within a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.