question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

GET with body sends as query string

See original GitHub issue

I have the following contract for a consumer. The request works when sending it to the server using Postman.

When the pact provider tries to verify it fails. The body is sent in the query string and not in the body of the GET request as expected.

Using the latest version of PactNet.

{
  "consumer": {
    "name": "Source System"
  },
  "provider": {
    "name": "Event API"
  },
  "interactions": [
    {
      "description": "A GET request with event filters",
      "providerState": "default state",
      "request": {
        "method": "get",
        "path": "/events",
        "headers": {
          "Content-Type": "application/json; charset=utf-8"
        },
        "body": {
          "filters": [
            {
              "type": "state",
              "source": "logs"
            },
            {
              "type": "information",
              "source": "memory"
            }
          ]
        }
      },
      "response": {
        "status": 200,
        "headers": {
          "Content-Type": "application/json; charset=utf-8"
        },
        "body": {
          "data": [
            {
              "id": 1,
              "event": "init",
            },
            {
              "id": 2,
              "event": "start",
            }
          ]
        }
      }
    }
  ],
  "metadata": {
    "pactSpecification": {
      "version": "2.0.0"
    }
  }
}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
neilcampbellcommented, Feb 5, 2019

@Nexith That’s going to be the ruby core doing that. Typically a body in a GET requests is not a good idea, purely because the HTTP 1.1 spec had language to indicate it should not be supported on the server side. I know now the spec has been amended, but still you run into compatibility issues like this one. I’d recommend changing your API to accept query params instead and updating the pact to use query, rather than body.

0reactions
adamrodgercommented, Aug 26, 2021

Should be fixed in 4.x with the move to Rust core instead of Ruby (or at least it’ll be broken in a differnt way 😁 )

Read more comments on GitHub >

github_iconTop Results From Across the Web

HTTP GET with request body
Yes, you can send a request body with GET but it should not have any meaning. If you give it meaning by parsing...
Read more >
HTTP GET with Request Body A Technical Deep Dive
HTTP GET with request body is a technique that allows you to send data in the body of the request, rather than in...
Read more >
Why an HTTP Get Request Shouldn't Have a Body
In this tutorial, we'll learn why an HTTP GET request shouldn't be sent with a body. First, we'll see why that request is...
Read more >
Use Case of HTTP GET Request with a Body
I am maintaining a old . aspx page in which all the data required by the page to show the content is passed...
Read more >
Should you send a payload in an HTTP GET request?
This is a perfect use case where the complex JSON query can be passed as a request body in the HTTP GET request,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found