Package: mkdocs-apicall-plugin
mkdocs-apicall-pluginAuto-generate code samples to make API callsInstallationpipinstallmkdocs-apicall-pluginThis plugin works with thematerialtheme and is built on top of thetabbedandsuperfencedextensions from PyMdown. Enable the extensions and the plugin in yourmkdocs.yml:theme:name:materialmarkdown_extensions:-pymdownx.superfences-pymdownx.tabbed:alternate_style:trueplugins:-apicallSyntaxThe syntax is given below. Basically it may look like a classical HTTP request message.@@@ <METHOD> <PATH> [<PAYLOAD>]
    [<HEADER-KEY>: <HEADER-VALUE>]
    [<HEADER-KEY>: <HEADER-VALUE>]The method and the paths are both mandatory.
One can append a payload (only a json for the moment) to the first line.
The following lines are extra indented HTTP headers.ConfigurationThe plugin supports few options:line_length[int] is the maximum length of a line of code before splitting into several lines.icons[bool] activates language icons. You must add the following extensions:markdown_extensions:# ...-attr_list-pymdownx.emoji:emoji_index:!!python/name:materialx.emoji.twemojiemoji_generator:!!python/name:materialx.emoji.to_svglanguages[list] filters the languages to display (show all by default). The order is also taken into account. The termlanguageis clearly a misuse as it rather refers to away to make the API call(so we may havecurl,wgetalong withtypescriptfor example). Currently3 languagesare supported:curl,pythonandjavascript.As an example you may have:plugins:-apicall:line_length:90icons:truelanguages:-curl-python-javascriptYou can also pass extra configuration to a language by adding some sub-keys:plugins:-apicall:line_length:90icons:truelanguages:-curl:options:-"-s"-python-javascriptCurrently onlycurlsupports theoptionssub-key to insert some CLI options.ContributingObviously, we need to dev morelanguagesand increase the number of features: HTTP options, language options, code formatting...How?Open an issue, we may possibly discuss about the requested feature and if we are OK, you can create a branch and submit PR.Developing a new languageTo add a new language, you have to create a new source code file inside themkdocs_apicall_plugin/folder.Basically a language looks as follows:from.abstractimportAPICallclassNewAPICall(APICall):# [unique] name of the language. This is what is displayed# in the tabsname:str="new"# material mkdocs icons (see https://squidfunk.github.io/mkdocs-material/reference/icons-emojis/)icon:str=":material-web:"# Pygments language for syntax highlighting# (see https://pygments.org/languages/)lang:str="shell"# Indentation when the call is wrapped into several lines# This is just for internal use (so it depends on how you# code the language)indent:str=" "*5defrender_code(self)->str:"""Single function to implement. It must return the rawstring that will be encapsulated in code blocks and tabs."""# TODOSo, you must implement a subclass ofAPICalland notably therender_codemethod. This method returns only the code as string,
as you may write in your favorite editor.You have access to several attributes:AttributeTypeDetails_methodabstract.HttpMethodLikeGETorPOST. This is always uppercase_urlstrAPI endpoint to reach_headersDict[str, Any]HTTP headers_bodystrRaw body as string (as it is written in the API call within the markdown source file)_max_line_lengthintMaximum line length desired_print_iconboolWhether the icon will be printed (normally it does have impact on your dev)_language_configdictLanguage specific configuration:warning: You are responsible of the possible default values of the_language_configattribute.:warning: You are encouraged to render code differently according to the value of_max_line_length. One may imagine at least aninlineand amultilinerendering.