Skip to content

Programmatically get request body data #718

Open
@sckott

Description

@sckott

via ropensci/vcr#276 discussion

There may be other use cases, but the use case for this right now is in vcr we want to record in a vcr cassette the same information that is sent in a real HTTP request for the request body.

There is httr2:::req_body_get() but it is not exported for one, for two it doesn't cover all body types, and three we'd need a way to gather the data that is sent in a real request for the request body.

One can run req_dry_run to see what is sent but AFAICT the request body data isn't available from that call anyway.

Ideally for the vcr use case there'd be a way to get the request body data as it would be sent in a real http request BEFORE making the request, because although we don't record the cassette until after the real request is made on first recording, on subsequent recordings of the matching request we'd need a way to determine the request body data WITHOUT having to make a real HTTP request (assuming that is, the user is matching on request body)

Activity

hadley

hadley commented on Apr 23, 2025

@hadley
Member

Also need to export req_method_get so you don't need webmockr:::req_method_get_w().

Or maybe we could export req_prepare() which does req_method_apply() and req_body_apply()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @hadley@sckott

        Issue actions

          Programmatically get request body data · Issue #718 · r-lib/httr2