You've already forked bthlabs-jsonrpc
Initial public releases
* `bthlabs-jsonrpc-aiohttp` v1.0.0 * `bthlabs-jsonrpc-core` v1.0.0 * `bthlabs-jsonrpc-django` v1.0.0
This commit is contained in:
43
packages/bthlabs-jsonrpc-core/docs/source/api.rst
Normal file
43
packages/bthlabs-jsonrpc-core/docs/source/api.rst
Normal file
@@ -0,0 +1,43 @@
|
||||
API Documentation
|
||||
=================
|
||||
|
||||
.. module:: bthlabs_jsonrpc_core
|
||||
|
||||
This section provides the API documentation for BTHLabs JSONRPC - Core.
|
||||
|
||||
Decorators
|
||||
----------
|
||||
|
||||
.. autofunction:: register_method
|
||||
|
||||
|
||||
Exceptions
|
||||
----------
|
||||
|
||||
.. autoexception:: BaseJSONRPCError
|
||||
:members:
|
||||
|
||||
.. autoexception:: JSONRPCAccessDeniedError
|
||||
:members:
|
||||
|
||||
.. autoexception:: JSONRPCInternalError
|
||||
:members:
|
||||
|
||||
.. autoexception:: JSONRPCParseError
|
||||
:members:
|
||||
|
||||
.. autoexception:: JSONRPCSerializerError
|
||||
:members:
|
||||
|
||||
Executor
|
||||
--------
|
||||
|
||||
.. autoclass:: Executor
|
||||
:members:
|
||||
|
||||
|
||||
Serializer
|
||||
----------
|
||||
|
||||
.. autoclass:: JSONRPCSerializer
|
||||
:members:
|
||||
57
packages/bthlabs-jsonrpc-core/docs/source/conf.py
Normal file
57
packages/bthlabs-jsonrpc-core/docs/source/conf.py
Normal file
@@ -0,0 +1,57 @@
|
||||
# Configuration file for the Sphinx documentation builder.
|
||||
#
|
||||
# This file only contains a selection of the most common options. For a full
|
||||
# list see the documentation:
|
||||
# https://www.sphinx-doc.org/en/master/usage/configuration.html
|
||||
|
||||
# -- Path setup --------------------------------------------------------------
|
||||
|
||||
# If extensions (or modules to document with autodoc) are in another directory,
|
||||
# add these directories to sys.path here. If the directory is relative to the
|
||||
# documentation root, use os.path.abspath to make it absolute, like shown here.
|
||||
#
|
||||
import os
|
||||
import sys
|
||||
sys.path.insert(0, os.path.abspath('../../'))
|
||||
|
||||
|
||||
# -- Project information -----------------------------------------------------
|
||||
|
||||
project = 'BTHLabs JSONRPC - Core'
|
||||
copyright = '2022-present Tomek Wójcik'
|
||||
author = 'Tomek Wójcik'
|
||||
version = '1.0.0'
|
||||
|
||||
# The full version, including alpha/beta/rc tags
|
||||
release = '1.0.0'
|
||||
|
||||
|
||||
# -- General configuration ---------------------------------------------------
|
||||
|
||||
# Add any Sphinx extension module names here, as strings. They can be
|
||||
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
|
||||
# ones.
|
||||
extensions = [
|
||||
'sphinx.ext.autodoc',
|
||||
]
|
||||
|
||||
# Add any paths that contain templates here, relative to this directory.
|
||||
templates_path = ['_templates']
|
||||
|
||||
# List of patterns, relative to source directory, that match files and
|
||||
# directories to ignore when looking for source files.
|
||||
# This pattern also affects html_static_path and html_extra_path.
|
||||
exclude_patterns = []
|
||||
|
||||
|
||||
# -- Options for HTML output -------------------------------------------------
|
||||
|
||||
# The theme to use for HTML and HTML Help pages. See the documentation for
|
||||
# a list of builtin themes.
|
||||
#
|
||||
html_theme = 'sphinx_rtd_theme'
|
||||
|
||||
# Add any paths that contain custom static files (such as style sheets) here,
|
||||
# relative to this directory. They are copied after the builtin static files,
|
||||
# so a file named "default.css" will overwrite the builtin "default.css".
|
||||
html_static_path = ['_static']
|
||||
18
packages/bthlabs-jsonrpc-core/docs/source/index.rst
Normal file
18
packages/bthlabs-jsonrpc-core/docs/source/index.rst
Normal file
@@ -0,0 +1,18 @@
|
||||
BTHLabs JSONRPC - Core
|
||||
======================
|
||||
|
||||
BTHLabs JSONRPC is a set of Python libraries that provide extensible framework
|
||||
for adding JSONRPC interfaces to existing Python Web applications.
|
||||
|
||||
The *core* package acts as a foundation for framework-specific integrations.
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 2
|
||||
|
||||
overview
|
||||
integrations
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 2
|
||||
|
||||
api
|
||||
30
packages/bthlabs-jsonrpc-core/docs/source/integrations.rst
Normal file
30
packages/bthlabs-jsonrpc-core/docs/source/integrations.rst
Normal file
@@ -0,0 +1,30 @@
|
||||
Integrations
|
||||
============
|
||||
|
||||
BTHLabs JSONRPC provides integration packages for specific Web frameworks.
|
||||
|
||||
Django
|
||||
------
|
||||
|
||||
Django integration is provided by ``bthlabs-jsonrpc-django`` package.
|
||||
|
||||
+-------------------+-----------------------------------------------------+
|
||||
| PyPI | https://pypi.org/project/bthlabs-jsonrpc-django/ |
|
||||
+-------------------+-----------------------------------------------------+
|
||||
| Docs | https://projects.bthlabs.pl/bthlabs-jsonrpc/django/ |
|
||||
+-------------------+-----------------------------------------------------+
|
||||
| Source repository | https://git.bthlabs.pl/tomekwojcik/bthlabs-jsonrpc/ |
|
||||
+-------------------+-----------------------------------------------------+
|
||||
|
||||
aiohttp
|
||||
-------
|
||||
|
||||
aiohttp integration is provided by ``bthlabs-jsonrpc-aiohttp`` package.
|
||||
|
||||
+-------------------+------------------------------------------------------+
|
||||
| PyPI | https://pypi.org/project/bthlabs-jsonrpc-aiohttp/ |
|
||||
+-------------------+------------------------------------------------------+
|
||||
| Docs | https://projects.bthlabs.pl/bthlabs-jsonrpc/aiohttp/ |
|
||||
+-------------------+------------------------------------------------------+
|
||||
| Source repository | https://git.bthlabs.pl/tomekwojcik/bthlabs-jsonrpc/ |
|
||||
+-------------------+------------------------------------------------------+
|
||||
89
packages/bthlabs-jsonrpc-core/docs/source/overview.rst
Normal file
89
packages/bthlabs-jsonrpc-core/docs/source/overview.rst
Normal file
@@ -0,0 +1,89 @@
|
||||
Overview
|
||||
========
|
||||
|
||||
This section provides the general overview of the library.
|
||||
|
||||
Installation
|
||||
------------
|
||||
|
||||
.. code-block:: shell
|
||||
|
||||
$ pip install bthlabs_jsonrpc_core
|
||||
|
||||
Usage
|
||||
-----
|
||||
|
||||
While this package is built to mostly support other integrations, it's possible
|
||||
to use it directly to add a JSONRPC endpoint to an existing Web app.
|
||||
|
||||
Consider the following Flask app:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from bthlabs_jsonrpc_core import Executor, register_method
|
||||
from flask import Flask, jsonify, request
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
|
||||
@register_method('hello')
|
||||
def hello(who='World'):
|
||||
return f'Hello, {who}!'
|
||||
|
||||
|
||||
@app.route('/rpc', methods=['POST'])
|
||||
def post_rpc():
|
||||
executor = Executor()
|
||||
serializer = executor.execute(request.get_data())
|
||||
|
||||
return jsonify(serializer.data)
|
||||
|
||||
This application will allow calling the ``hello`` JSONPRC method via the
|
||||
``POST /rpc`` endpoint. This approach is limited, as it doesn't provide the
|
||||
means of performing any access control and other checks, leaving the app to
|
||||
do this. In practice, it's best to rely on framework integrations.
|
||||
|
||||
Calling Conventions
|
||||
-------------------
|
||||
|
||||
The JSONRPC 2.0 spec calls for two conventions for passing method parameters -
|
||||
*by-position* (using an array) or *by-name* (using a JSON object). BTHLabs
|
||||
JSONRPC implements both.
|
||||
|
||||
The ``hello`` method from the Flask app example could be called using the
|
||||
following payloads.
|
||||
|
||||
.. code-block:: json
|
||||
|
||||
{
|
||||
"jsonrpc": "2.0",
|
||||
"id": "hello"
|
||||
}
|
||||
|
||||
This payload would call the method without arguments. In this case, it would
|
||||
return ``Hello, World!``.
|
||||
|
||||
.. code-block:: json
|
||||
|
||||
{
|
||||
"jsonrpc": "2.0",
|
||||
"id": "hello",
|
||||
"params": ["JSONRPC"]
|
||||
}
|
||||
|
||||
This payload would call the method with one positional argument. In this case,
|
||||
it would return ``Hello, JSONRPC!``.
|
||||
|
||||
.. code-block:: json
|
||||
|
||||
{
|
||||
"jsonrpc": "2.0",
|
||||
"id": "hello",
|
||||
"params": {"who": "JSONRPC"}
|
||||
}
|
||||
|
||||
This payload would call the method with one keyword argument. In this case,
|
||||
it would return ``Hello, JSONRPC!``.
|
||||
|
||||
While writing your methods, you should consider these conventions and specify
|
||||
your method signatures accordingly.
|
||||
Reference in New Issue
Block a user