Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make HTTP calls in docs more readable (and maybe testable) #196

Closed
tisto opened this issue Feb 15, 2017 · 7 comments
Closed

Make HTTP calls in docs more readable (and maybe testable) #196

tisto opened this issue Feb 15, 2017 · 7 comments

Comments

@tisto
Copy link
Member

tisto commented Feb 15, 2017

Writing docs for plone.restapi is currently a pain. Say I want to write down an example for sending a POST request with some payload:

    POST /folder HTTP/1.1
    Host: localhost:8080
    Accept: application/json
    Content-Type: application/json

    {
        '@type': 'Document',
        'title': 'My Document',
    }

What I have to actually write is this:

.. example-code::

  .. code-block:: http-request

    POST /folder HTTP/1.1
    Host: localhost:8080
    Accept: application/json
    Content-Type: application/json

    {
        '@type': 'Document',
        'title': 'My Document',
    }

  .. code-block:: curl

    curl -i -H "Accept: application/json" -H "Content-type: application/json" --data-raw '{"@type":"Document", "title": "My Document"}' --user admin:admin -X POST http://localhost:8080/Plone/folder

  .. code-block:: httpie

    http -a admin:admin POST http://localhost:8080/Plone/folder \\@type=Document title=My Document Accept:application/json

  .. code-block:: python-requests

    requests.post('http://localhost:8080/Plone/folder', auth=('admin', 'admin'), headers={'Accept': 'application/json'}, json={'@type': 'Document', 'title': 'My Document'})

This is not only a lot of work to write, but also error prone. This approach will also not scale if we want to include more options. I guess it should be possible to auto-generate the curl, httpie, or python-requests examples from the initial pseudo-code HTTP request. Thanks to @svx we already have a library that renders the latter. I'm wondering if we could write a sphinx library that makes writing plone.restapi docs fun again. If we have such a library, we might be able to make the examples testable as well (doctests on speed).

@datakurre you have some experience with writing sphinx docs extensions. what do you think, is that doable?

@datakurre
Copy link
Member

datakurre commented Feb 15, 2017 via email

@lukasgraf
Copy link
Member

I agree, this bothers me as well. Not only is it cumbersome to write those examples by hand, but the URLs used in them also differ from test_documentation.py generated snippets (http://localhost:55001/plone vs. http://localhost:8080/Plone), as does the assumed content structure.

All this ties into acceptance testing and keepingplone.server in sync as well (see #162 / #137).

I don't have time to look at this in depth right now (swamped in work), but I'm very interested in working in this, possibly at the sprint.

@datakurre
Copy link
Member

Would it be ok to have original pseudo-examples in docs inline and generate both documentation examples and tests from those? Or something else? I could work on the Sphinx plugin during the sprint. Anything should be possible :)

@tisto
Copy link
Member Author

tisto commented Feb 27, 2017

@datakurre I would say ideally we would generate the real world examples from our pseudo-examples. The docs writer would just write the pseudo calls and the sphinx extension would auto-generate the real-world examples from this. Maybe it is sufficient if we test our sphinx extension properly.

@datakurre
Copy link
Member

@lukasgraf Are you still interested in working with this with me on the sprint?

I'm planning an independent Sphinx-plugin (at least one new package), which could

  • parse pseudo examples and generate real examples
  • has new directive to replace pseudo examples with generated examples in Sphinx code
  • has test utility to collect examples as executable tests with configurable test fixture (pytest, plone.testing)

It should be possible to work with any of these independently.

@tisto What kind of tests would you like to be generated from the pseudo code? Just python-test using requests-library or should the tests use the tools in generated examples? Or both? Which one is the priority?

@tisto Do you already have more pseudo-examples (in addition to the one in this ticket) available somewhere?

@datakurre
Copy link
Member

@tisto
Copy link
Member Author

tisto commented Mar 10, 2017

Wohoo! (sorry for doing this over and over again).

@tisto tisto closed this as completed Mar 10, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants