1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

PythonのマイクロフレームワークBottleを触った

Last updated at Posted at 2020-03-15

Bottleとは

https://bottlepy.org/docs/dev/
PythonのマイクロWebフレームワークです。Webアプリケーションを構築する上で必要最低限の機能のみが提供されておりちょっとしたアプリケーションを作るのに使う感じ。
今回はPythonでいい感じにRoutingしたかったので採用。

インストール

pip3 install bottle

Routing

Routeデコレータ(@route)をつけることでRoutingが行われるらしい

# index.py

@route('/')
def index():
  return [json.dumps({'message':'hoge'}).encode("utf-8")]

サーバー起動

run関数を使う。先ほどのファイルでrun関数を呼び出し。

# index.py

@route('/')
def index():
  return [json.dumps({'message':'hoge'}).encode("utf-8")]

run(host='localhost', port=3001)

index.pyを実行すると

python3 index.py
Listening on http://localhost:3001/
Hit Ctrl-C to quit.

サーバー起動

確認

curl http://localhost:3001/
{"message": "hoge"}

無事レスポンスが返ってきた

1
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?