Skip to content

feat: add HTTP method override option #3910

Closed

Description

@KATT

Describe the feature you'd like to request

Make it possible to handle biiiiig input payloads on queries by allowing queries to be sent through HTTP POST.

Describe the solution you'd like to see

  • allowOverride: boolean on HTTP adapters
    • With this option enabled, we can ignore the checks that make sure that queries are called with GET and mutations as POST
  • A custom link that allows you to remap all queries on the upstream as a POST or allow httpBatchLink to have some option for it

Describe alternate solutions

#3590

Additional information

No response

👨‍👧‍👦 Contributing

  • 🙋‍♂️ Yes, I'd be down to file a PR implementing this feature!

TRP-58

Activity

  1. changed the title [-]feat: add method override option[/-] [+]feat: add HTTP method override option[/+] on Mar 3, 2023
  2. Nick-Lucas commented on Mar 3, 2023

    @Nick-Lucas
    Contributor

    I agree this needs solving, it was next on my mental list to have a look at based on the number of help topics I've seen with size issues.

    Is there a reason that GET is necessary at all? Would it be a problem if all invocations were changed to POST with a body rather than adding more configurability?

    Some thoughts of my own:

    • GET/POST are meaningful in REST, but that doesn't necessarily matter as much for RPC
    • URI encoded GET queries are hard to debug from the network debugger, so moving the query into the body would help a lot with the understandability of what tRPC is doing under the hood
  3. juliusmarminge commented on Mar 3, 2023

    @juliusmarminge
    Member

    GET/POST are meaningful in REST, but that doesn't necessarily matter as much for RPC

    We have tRPC OpenAPI that lets you expose your trpc router as a rest api though

  4. Nick-Lucas commented on Mar 3, 2023

    @Nick-Lucas
    Contributor

    Good point, I haven't used it though. I take then it doesn't proxy tRPC with restful methods, it just generates the schema with GET and POST in?

  5. KATT commented on Mar 4, 2023

    @KATT
    MemberAuthor

    Is there a reason that GET is necessary at all? Would it be a problem if all invocations were changed to POST with a body rather than adding more configurability?

    HTTP-level caching is nice to be able to have

  6. dtinth commented on Apr 12, 2023

    @dtinth
    Contributor

    Some prior art in Ruby world: Rack::MethodOverride allows specifying the method via a special parameter _method.

    It may be possible to allows sending GET requests as POST by applying the same concept, something like:

    POST /procedure
    Content-Type: x-www-form-urlencoded
    
    _method=GET&input={"x":1}
    
  7. KATT commented on Apr 12, 2023

    @KATT
    MemberAuthor

    Yup, _method is what I'm thinking too

  8. changed the title [-]feat: add HTTP method override option[/-] [+][TRP-58] feat: add HTTP method override option[/+] on May 25, 2023
  9. changed the title [-][TRP-58] feat: add HTTP method override option[/-] [+]feat: add HTTP method override option[/+] on May 25, 2023
  10. AlonMiz commented on Oct 26, 2023

    @AlonMiz

    Totally agree, I find myself trying to read the URL sometimes and my head explodes. it would be super useful to allow ALL params being passed in the request body.
    eg. search with useInfiniteQuery, passing many complex filters (dates, numbers, strings) and params, hard to tell between queries, hard to tell what's been sent to the server.
    in general, whenever I'm implementing search in a regular app, I would choose POST /items/search
    so I can pass params freely without fearing of encoding and the body is human-readable and predictable.

  11. KATT commented on Nov 24, 2023

    @KATT
    MemberAuthor

    Added a failing test suite in #5099 if someone wants to pick it up

  12. VictorGlindasPaf commented on Jan 18, 2024

    @VictorGlindasPaf

    This would be fantastic. We have the requirement that we are not allowed to send values as query parameters, as each request gets logged and may contain sensitive information in the URL.

    So I've currently added a TRPC patch to always use POST for queries, but having it built in would be super.

  13. KATT commented on Feb 29, 2024

    @KATT
    MemberAuthor

    This feature has been added in the next-branch of tRPC, meaning it is available in v11 of tRPC.

    It's possible to start using it today, have a look at the migration guide for more info: https://trpc.io/docs/migrate-from-v10-to-v11

  14. github-actions commented on Mar 1, 2024

    @github-actions
    Contributor

    This issue has been locked because we are very unlikely to see comments on closed issues. If you are running into a similar issue, please create a new issue. Thank you.

  15. locked as resolved and limited conversation to collaborators on Mar 1, 2024
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

    ✅ accepted-PRs-welcomeFeature proposal is accepted and ready to work on

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions