This commit is contained in:
2025-04-08 06:38:30 +03:00
parent df9690468a
commit 9f9134ca98
10 changed files with 39 additions and 72 deletions

View File

@@ -1,35 +0,0 @@
@ECHO OFF
pushd %~dp0
REM Command file for Sphinx documentation
if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=source
set BUILDDIR=build
if "%1" == "" goto help
%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.https://www.sphinx-doc.org/
exit /b 1
)
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
goto end
:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
:end
popd

View File

@@ -30,4 +30,4 @@ def raise_error() -> bool:
jsonrpc['raise.error'] = raise_error
app.run(host='0.0.0.0', debug=True)
app.run(host='0.0.0.0', port=5500, debug=True)

View File

@@ -1,4 +1,4 @@
Flask
=====
.. literalinclude:: flask.py
.. literalinclude:: example.py

View File

@@ -0,0 +1,19 @@
from jsonrpc.client import Client
request = {
"jsonrpc": "2.0",
"method": "app.endpoint",
"params": {"a": 1, "b": 2},
"id": "1"
}
client = Client('http://127.0.0.1:5000/api')
response = client(request)
assert 'result' in response, response['error']['message']
if 'result' in response:
print(response['result'])
elif 'error' in response:
print(response['result'])
print(response)

View File

@@ -1,24 +1,8 @@
Использование
=============
.. code-block:: python
.. literalinclude:: usage.py
from jsonrpc import JSONRPC
.. literalinclude:: server-usage.py
jsonrpc = JSONRPC()
@jsonrpc.method('app.endpoint')
def app_endpoint(a: int, b: int) -> int:
result = a + b
return result
request = {
"jsonrpc": "2.0",
"method": "app.endpoint",
"params": {"a": 1, "b": 2},
"id": "1"
}
response = jsonrpc(request)
print(response)
.. literalinclude:: client-usage.py