There are a few web apps I use, for which I would like to develop code. There are others who I see doing this on GitHub for some of the same apps. The tricky part is that there are no published API docs for these services. How can I infer what the API calls should look like?
Somehow, other coders are able to figure out what the API calls should look like and write code that interactively builds calls and submits them to the sites.
I suppose they must do this by analyzing the site with browser-based dev tools, like the ones built into Chrome and Firefox (?) but when I try that it's still not obvious. Although the browser For example, @castlelemongrab is developing the parlance
library / tool for Parler.com, although there's no published API. His library builds URL-based calls, but when I repeat the actions in my browser I never see the URL's displayed that show the format I'd need to construct to carry out the actions in an application (example: to make a post his queries use the format v1/post?id=xxxxxx
). Since I can't figure out how he determined that format, I also can't figure out how to write the code for the missing functionality that I'd like to add.
If he is writing code to pass URL parameters (which appears to be the case), you need to look in the Developer console and "inspect" the request. It gives you everything from the URL (and URL query parameters) to the expected headers and response code etc. You just need to recreate exactly what the browser is doing. Make sure to pay attention to the Content-Type as well... probably url-encoded form data since this isn't an "API" but a website/webapp. The inspector should also show the exact parameters passed if there is form data etc in the POST request.
For example... lets say you want to submit some HTML in your program to https://validator.w3.org/#validate_by_input
to check if it's valid.
Physically go to that URL first and try inspecting the request that is sent when the the Check
button is pressed. Then compare it to this code:
>>> from requests import post
>>> html_str = """
... <!DOCTYPE html>
... <html>
... <body>
...
... <h1>This is heading 1</h1>
...
... </body>
... </html>"""
>>>
>>> from requests import post
>>>
>>> def html_validator(html_str):
... p = {'fragment': html_str, 'content': 'submit'}
... _ = [print(out) for out in post('https://validator.w3.org/check', files=p).text.split('<')]
...
>>>
>>>
>>> html_validator(html_str)
You'll see it's similar to making an API call, but really you are just submitting a form with some data (the same thing a user does in the browser when they press the button). Inspect the HTML form as well if you are unsure where the 'fragment' or 'content' comes from.... It's usually an HTML id or name attribute. Also make sure to "inspect" that check button... you'll see an ID or Name called "submit".
Your request inspector should have all the details, just mimic them with your code: