Lurker News
Effortlessly discover API behaviour with a Chrome extension that automatically generates OpenAPI specifications in real time for any app or website.

Comments (102) 40 threads

Show all comments

Showing thread 4 of 40

archiewood7 replies#
My most common use case here is to then want to hit the API from python, and adjust the params / url etc.

Would love a "copy to python requests" button that
grabs the headers
generates a boilerplate python snippet including the headers and the URL:

    import requests
    import json

    url = ''

    headers = {
        'User-Agent': 'Mozilla/5.0 ...',
        ...
    }

    data = {
        "page": 5,
        "size": 28
        ...
    }

    response = requests.post(url, headers=headers, data=json.dumps(data))

    if response.status_code == 200:
        print(response.json())
    else:
        print(f"Error {response.status_code}: {response.text}")
ea0164 replies#
Steps to do so:

- open the network console
- right click on the request
- click "copy as curl"
- visit https://curlconverter.com/ to convert to Python/Node/any language

tilne#
Thank you for this. I didn’t know curlconverter existed.
MurageKabui#
I was to say this lol
archiewood1 reply#
This is my current workflow, though with ChatGPT.

I was just trying to save a few clicks

novia#
You made your request sound important to implement when you already have a workaround that doesn't take very much time...

This is why feature bloat is a thing

yread#
wow what a perfect service to steal session cookies
knowsuchagency#
You could take the OpenAPI json generated from this project and feed it to https://docs.scalar.com/swagger-editor which generates boilerplate in several formats, including Python
gabrielsroka#
1. You should almost always use requests.Session() instead of requests. It's faster, and can make the code shorter.

2. requests can dump to JSON for you by using json=, so you don't need a separate module. It'll even set the content-type header to application/json for you.

  import requests

  url = ''

  headers = {
      'User-Agent': 'Mozilla/5.0 ...',
      ...
  }

  session = requests.Session()
  session.headers.update(headers)

  data = {
      "page": 5,
      "size": 28
      ...
  }

  response = session.post(url, json=data)

  if response.status_code == 200:
      print(response.json())
  else:
      print(f"Error {response.status_code}: {response.text}")
westurner#
SeleniumIDE can record and save browser test cases to Python: https://github.com/SeleniumHQ/selenium-ide

awesome-test-automation/python-test-automation.md lists a number of ways to wrap selenium/webdriver and also playwright: https://github.com/atinfo/awesome-test-automation/blob/maste...
vcr.py, playback, and rr do [HTTP,] test recording and playback. httprunner can record and replay HAR. DevTools can save http requests and responses to HAR files.
awesome-web-archiving lists a number of tools that work with WARC; but only har2warc: https://github.com/iipc/awesome-web-archiving/blob/main/READ...