Create HTTP client from pydoc
Project description
*******
Doclink
*******
.. image:: https://travis-ci.org/Luoyufu/doclink.svg?branch=master
:target: https://travis-ci.org/Luoyufu/doclink
.. image:: https://codecov.io/gh/Luoyufu/doclink/branch/master/graph/badge.svg
:target: https://codecov.io/gh/Luoyufu/doclink
| Build client for Web APIs from pydoc. Inspired by `Uplink <https://github.com/prkumar/uplink>`_.
Overview
========
| Doclink turns a Python function into HTTP API by writting pydoc to declare the api meta.
| It is based on Requests and uses YAML with predefined schema as api declaration.
| When calling the function, response from HTTP API will be passed in as a parameter for futher handling.
Features
========
* create python function as HTTP API with **pydoc**
* **YAML** based schema for api declaration
* handle api response in the **same** function
* response hook as **middleware**
* **all** args for Requests supported
* select base_uri dynamicly from simple **router**
Quick through, with httpbin
=====
Create a consumer instance.
.. code-block:: python
from doclink import Consumer
consumer = Consumer('http://httpbin.org/')
Add response hook(middleware).
.. code-block:: python
@consumer.resp_hook
def json_hook(resp):
resp.json = resp.json()
Add function for api declaration.
.. code-block:: python
@consumer.get('get')
def get(resp):
"""
<meta>
args:
query:
- arg1: arg1
- arg2: arg2
</meta>
"""
return resp.json['args']
Use you api.
.. code-block:: python
>>> get()
{
"arg1": "arg1",
"arg2": "arg2"
}
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
doclink-1.0.2.tar.gz
(10.3 kB
view hashes)
Built Distribution
Close
Hashes for doclink-1.0.2-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5d25e0932aa0ae8b94bdf5cc86d1297bd7450ad287a0c1a10ba4c7ddb5800bb7 |
|
MD5 | ced97d64e6f1f81feace0b51b055386d |
|
BLAKE2b-256 | 874c76a5f506fd70c38a1e2629f7e9f191c7eba4717e9e0b69d1546c6332395a |