Hi! I am trying to do basic stubbing with JSON (fo...
# help
a
Hi! I am trying to do basic stubbing with JSON (follow this doc), using the first example. However, when I use Postman to make a GET request to
http://localhost:8080/some/thing
, it just returns a "Not Found" error. Does anyone know what might be causing this problem, such as if I'm not starting WireMock properly, etc.? For context, my .json file is in a folder, and I moved into the auto-generated mappings folder
b
What does your mapping file look like? And obvious question is obvious, but have you started WireMock and is it running on port 8080?
a
@Bas DijkstraThe mapping file is nearly the same as the example, which is the following:
Copy code
{
  "request": {
    "method": "GET",
    "url": "/api/repo/bitbucket.org/atlassian/nodejs-stack-tools-api/some_url/persist"
  },
  "response": {
    "status": 429,
    "body": "Hello, world!",
    "headers": {
      "Content-Type": "text/plain"
    }
  }
}
And I'm actually not sure if I started WireMock correctly, which might be the problem? I followed this doc, and ran this command to start a Docker image (so, not on port 8080 because my application I'm trying to use WireMock on is running on 8080). I don't know if this is the right way to start WireMock, and/or if there's more to it:
Copy code
docker run -it --rm \
  -p 8082:8080 \
  --name wiremock \
  -v $PWD:/home/wiremock \
  wiremock/wiremock:3.7.0
b
So, do you have a stub mapping for a GET to
/some/thing
? Or are you actually calling the endpoint you mentioned in the stub mapping? Does WireMock respond with a 404, or does it not respond at all?
a
Oh maybe I misinterpreted, I thought the json file was the stub mapping for
/some/thing
, and I was sending a GET request to
http://localhost:8080/some/thing
in Postman. And in Postman, it responds with Not Found, and actually I do see a 404 in my terminal (a snippet of it below):
Copy code
9,"method":"GET","host":"localhost:8080","remoteAddress":"::ffff:172.26.0.5","remotePort":50126,"url":"/some/
thing","ep":"GET /some/thing"},"res":{"headers":{"content-length":"9","content-type":"text/plain; charset=utf-8","x-b3
spanid":"4b26db6f8b9d1a2c","x-b3-traceid":"71c378849de171a0"},"ts":1719511327829,"time":10,"statusCode":404,"length":
9}}
b
It will only respond if the URL matches the one in the mapping file, if WireMock doesn’t know how to respond, it will send a default response which is a 404
a
Oh right, thank you! I realized something in the meantime: I changed my GET request to hit
<http://localhost:*8082*/api/repo/bitbucket.org/atlassian/nodejs-stack-tools-api/some_url/persist>
instead of 8080, which seemed to help because I now receive a different error:
No response could be served as there are no stub mappings in this WireMock instance.
Looking into documentation, it seems to say WireMock expects stub files in
home/wiremock/mappings
in the Docker container, which I'm not sure how to exactly achieve... I'm not sure if this is on the right track?
b
I’ve not really worked that much with the Docker instance but the regular standalone WireMock creates the
mapping
and
__files
folders automatically when it first starts. Maybe someone else can shed more light on this?
👍 1
l
Hi @Angela Yuan it looks like you are not mapping your local directories when you are starting docker. This is why wiremock running in docker can’t find any mapping files. I setup an example project for wiremock running in docker which might help you get yours setup https://github.com/leeturner/wiremock-standalone-docker-example
🙌 1
a
Thank you so much! I will take a look into this!
703 Views