Skip to main content

a http client based on requests just like Flask

Project description

Clask

PyPI PyPI - Downloads PyPI - Python Version PyPI - License

Github:https://github.com/mouday/Clask

简介

Clask: a http client based on requests just like Flask

对比:

- 描述 运行环境
Flask 路由映射到方法 服务端
Clask 方法映射到路由 客户端

安装

pip install clask

使用示例

1、Flask作为服务器代码

# -*- coding: utf-8 -*-

from flask import Flask, jsonify

app = Flask(__name__)


@app.route("/get")
def get():

    data = {
        "name": "Tom",
        "age":23
    }

    return jsonify(data)


if __name__ == '__main__':
    app.run(debug=True)

2、Clask作为客户端的代码

# -*- coding: utf-8 -*-

from clask import Clask

api = Clask(base_url="http://127.0.0.1:5000")


# 发送get请求
@api.route("/get")
def get():
    pass


if __name__ == '__main__':
    get()
    # '{"name": "Tom", "age": 23}'

其他示例

# 发送get请求
@api.get("/get")
def get():
    pass

# 发送get请求
@api.post("/post")
def post():
    pass


# 前置处理器
@api.before_request
def before_request(options):
    print('before_request::', options)
    return options


# 后置处理器
@api.after_request
def after_request(response):
    print('after_request', response.status_code)
    return response.json()


# 异常处理器
@api.error_handler
def error_handler(e):
    print(e)
    return None

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

clask-0.0.5.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

clask-0.0.5-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file clask-0.0.5.tar.gz.

File metadata

  • Download URL: clask-0.0.5.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.40.0 CPython/3.7.0

File hashes

Hashes for clask-0.0.5.tar.gz
Algorithm Hash digest
SHA256 79b04e96ffcb1262b9f415c35dac1cbe90b6136a3f0003af3a4791df157bb963
MD5 ed3378c840fc872fb487ab8a6c30c8ea
BLAKE2b-256 475937fe0e61efb377c4a65c8bc3669869b56ec246a9f36bffcd02332fd54999

See more details on using hashes here.

File details

Details for the file clask-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: clask-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 6.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.40.0 CPython/3.7.0

File hashes

Hashes for clask-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 c86d4d7d238764e87143a6e73cc23a5cd5e053224c6f515715e0008e68da8525
MD5 89bcf4715fe8d5a95d3ff5d2ad4c2449
BLAKE2b-256 7f44b623adf5519dd39a2fdc4e76b054892c91e89aeedfc74af0d20fadaf2497

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page