easy api maker for flask
Project description
flaspi (easy api maker for flask)
下の方に日本語の説明があります
Overview
- A tool to create flask APIs easily.
- API for sending and receiving JSON
- Note that it is not a strict RESTful API.
Usage example
- Server side
import flask
import flaspi
# Define a flask app (web server)
app = flask.Flask(__name__)
# function describing the API behavior
def greeting_func(req_obj):
return {"message": "Hello, %s!!"%req_obj["name"]}
# Define the API for post (params: the URL path, the function that defines the API action, and the flask app)
flaspi.post_api("/greeting", greeting_func, app = app)
# run flask server
app.run(host = "0.0.0.0", port = "80", debug = False)
- Example API call
curl http://localhost:80/greeting -X POST -H "Content-Type: application/json" --data '{"name": "Hoge"}'
- Result (response)
{"message": "Hello, Hoge!"}
- Example of API call (using flaspi)
res = flaspi.call_post_api("http://localhost:80/greeting", {"name": "Hoge"}) # -> (200, '{\n "message": "Hello, Hoge!!"\n}')
概要
- flaskのAPIを簡単に作れるツール
- JSONを送受信する形のAPI
- 厳密なRESTful-APIではないので注意
使用例
- サーバー側
import flask
import flaspi
# flaskのアプリ(ウェブサーバー)を定義
app = flask.Flask(__name__)
# APIの動作を記述した関数
def greeting_func(req_obj):
return {"message": "Hello, %s!!"%req_obj["name"]}
# postのAPIを定義 (URLのパス、動作を定義した関数、flaskのappを渡す)
flaspi.post_api("/greeting", greeting_func, app = app)
# flaskサーバー立ち上げ
app.run(host = "0.0.0.0", port = "80", debug = False)
- APIの呼び出し例
curl http://localhost:80/greeting -X POST -H "Content-Type: application/json" --data '{"name": "Hoge"}'
- 結果 (レスポンス)
{"message": "Hello, Hoge!!"}
- APIの呼び出し例 (flaspiを利用した場合)
res = flaspi.call_post_api("http://localhost:80/greeting", {"name": "Hoge"}) # -> (200, '{\n "message": "Hello, Hoge!!"\n}')
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
flaspi-0.0.3.tar.gz
(3.4 kB
view details)
Built Distribution
File details
Details for the file flaspi-0.0.3.tar.gz
.
File metadata
- Download URL: flaspi-0.0.3.tar.gz
- Upload date:
- Size: 3.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fbddcc37227c78949b4063a0174d1f6715563e5eda668e115771f210d4dede69 |
|
MD5 | 21dd56a1d58b373e6e2b4cc9b0a58c17 |
|
BLAKE2b-256 | 4a4283d174b8c4a89f098f6149a2b15d16357302e67678f087e6c1d88101b492 |
File details
Details for the file flaspi-0.0.3-py3-none-any.whl
.
File metadata
- Download URL: flaspi-0.0.3-py3-none-any.whl
- Upload date:
- Size: 3.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | aea57663abf9164608dde292789b95dcb265f3fb550ec6d4594eb532c8a7825e |
|
MD5 | f38db8878f251fc065cf30deaffd5088 |
|
BLAKE2b-256 | bc49de56904b9e9a3701d9d9782404b034e49a7639ced1e58ffa65fb9067985c |