Skip to main content

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!"}

概要

  • 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!!"}

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.1.tar.gz (2.9 kB view details)

Uploaded Source

Built Distribution

flaspi-0.0.1-py3-none-any.whl (3.1 kB view details)

Uploaded Python 3

File details

Details for the file flaspi-0.0.1.tar.gz.

File metadata

  • Download URL: flaspi-0.0.1.tar.gz
  • Upload date:
  • Size: 2.9 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

Hashes for flaspi-0.0.1.tar.gz
Algorithm Hash digest
SHA256 ae74b6bdd408f6c81f0aff7541cb68123b47b69ef33cc519415769b97c1901ca
MD5 cd36f8fcc0732a71ef1d85acc3932f0c
BLAKE2b-256 b93c42cb4298b9233932b122cf0a4b07417a128933ccd7382e53fa5b8764ee74

See more details on using hashes here.

File details

Details for the file flaspi-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: flaspi-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 3.1 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

Hashes for flaspi-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d7e106acf025068f52921c4cd3471d88fd54ce772a6aad1366e359acbd27707d
MD5 02a347d51a7790424736da3e3e7734a4
BLAKE2b-256 180f6d92942af2f615d58d168e0e978b13e538f2c48ed8fe6e6270259df55372

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