スポンサーリンク

Flask-RESTfulを試してみる

FlaskでAPIをtryしてみたい。

=> <2017/10/31 追記>
FlaskはすでにWEB APIでした。。。
私は勝手に、templates/ フォルダを作成し、viewを作らなければならないと勘違いしていました。templates/ フォルダを作成しないで、そのまま、WEB APIとして利用できるんですね、、、

——————————————

以下のものを試してみる。

http://flask-restful.readthedocs.io/en/0.3.5/
image

(環境)

(1)以下を参考にflask-restfulをインストール

http://flask-restful.readthedocs.io/en/0.3.5/installation.html

Anaconda Promptで、以下を入力

pip install flask-restful

image

image

(2)Hello Wordlしてみる

c:/py/flask_restful/ フォルダに、api.py を作成し、以下のサイトのコードをコピペ。

image

Anaconda Promptで、以下を入力

$ python api.py

image

WEBブラウザで、localhost:5000/ を開く

image

image

いい感じ。

(3)todoリストの以下のサイトのコードをコピペ

http://flask-restful.readthedocs.io/en/0.3.5/quickstart.html#full-example

image

image

Anaconda Promptで、以下を入力

$ python todo_api.py

コマンドプロンプト

curl http://localhost:5000/todos

image

その他

image

image

image

image

image

ちゃんとCRUDが、GET, POST, PUT, DELETEでできている。

が、ここから先が全く分からない。

2015-11-02
Flask-Restful
http://kzky.hatenablog.com/entry/2015/11/02/Flask-Restful

20141213
FlaskでPOST/GETつくってみた
http://kobashing.hatenablog.com/entry/%3Fp%3D138

これかな!?写経してみる

(4)

そのままではうまく動かない

少し変更してみるが、なかなかうまくいかない。

未完成だが、コードをめもしておく。

スポンサーリンク

Python

Posted by twosquirrel