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 hashes)

Uploaded source

Built Distribution

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

Uploaded py3

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