【Python】たった5行でAPIを作れる、そうbottleならね | 瀬戸内の雲のように

【Python】たった5行でAPIを作れる、そうbottleならね

Posted: 2018-08-17


スポンサーリンク

目次

背景

私は日常的にAPIを触ることが多いのですが、その中でAPIのスタブ(開発用に使う簡易的な環境)を作りたいと思うことがあります。

これまでは過去に作ったrailsの環境を使いまわしていたのですが、もっと簡単な方法がないかと思い、調べました。

すると、pythonのbottleを使うとものすごく簡単にAPIが作れることがわかりましたので、メモしておきます。

 

bottleとは

簡易的なWebアプリケーションを作るためのフレームワークです、railsやdjangoの簡単なやつ、と思ってもらえればと思います。

bottleのインストール方法

CentOS7でのインストール手順は以下の通りです。

# easy_install pip
# pip install bottle

これだけでOKです。とっても簡単です。

APIのソースコード

早速ですが、APIのソースコードです。

# -*- coding:utf-8 -*-
from bottle import route, run, Bottle, request

@route('/hello')
def hello():
    return '{"message": "Hello, this is aws"}'

run(host='0.0.0.0', port=8080, debug=True)

 

APIを実行してみる

以下コマンドで起動できます。

$ python api.py

 
curlしてみると、こんな感じです。

$ curl -D - http://localhost:8080/hello
127.0.0.1 - - [17/Aug/2018 03:21:03] "GET /aws HTTP/1.1" 200 33
HTTP/1.0 200 OK
Date: Fri, 17 Aug 2018 03:21:03 GMT
Server: WSGIServer/0.1 Python/2.7.13
Content-Length: 33
Content-Type: text/html; charset=UTF-8

{"message": "Hello, this is aws"}

レスポンスとして設定したjsonが返ってきました。

このように、bottleを使うととても簡単にAPIを作ることができます。


スポンサーリンク




コメント一覧

2022/05/21 02:23:06

JolwAudircurnさん

viagra online buy can you buy viagra in mexico https://aviagrasbt.com/


2022/04/08 05:23:41

Keezexictさん

metabolism tadalafil tadalafil 2o mg cvs


2022/04/08 12:26:07

Ntfbfplugsさん

cialis cost cialis without a prescription


2022/04/08 18:10:48

Fnenvunnyさん

viagra online without prescription viagra pills


2022/04/09 09:42:06

Dbngplugsさん

sildenafil pde5 sildenafil 50mg tablet


2022/04/10 05:44:06

Crnnwongeさん

viagra overdose brand name viagra order viagra online generic viagra online


2022/04/10 21:35:24

AndaAudircurnさん

c-tadalafil tadalafil 20mg dosage


2022/04/12 01:09:32

Kbwnexictさん

how to buy over the counter viagra best generic sildenafil


2022/04/12 09:25:19

Nmioplugsさん

sildenafil citrate canadian pharmacy which canadian pharmacies are legitimate


2022/04/12 14:41:55

Fwbnvunnyさん

how much sildenafil is in viagra online sildenafil


2022/04/13 05:58:21

Dennplugsさん

cvs pharmacy store ads what canadian pharmacies are legitimate


2022/04/13 18:57:42

Knrnexictさん

drugstore beetle homeopathic pharmacy online


2022/04/14 01:00:33

Nbttplugsさん

where to buy cialis from canada cialis viagra sales


2022/04/14 06:06:29

Fuupvunnyさん

30 mg sildenafil buy online can you buy viagra mexico


2022/04/14 21:37:45

Dsnnplugsさん

online pharmacy adipex canadian pharmacies drug prices


2022/04/15 16:33:07

Ckanwongeさん

levitra 10 mg schmelztabletten viagra vs cialis vs levitra forum


2022/04/16 02:31:54

AnuoAudircurnさん

canada drugs reviews canadian pharmacy generic levitra


2022/04/16 20:20:53

Enrnexictさん

buy cialis without doctor prescription how long does it take for cialis to work


2022/04/17 03:26:51

Zbttplugsさん

ivermectin otc heartgard plus ivermectin pyrantel


2022/04/17 06:57:52

Auupvunnyさん

cialis tadalafil 20mg sildenafil vs tadalafil


2022/04/18 01:34:41

Jtnnplugsさん

how long is ivermectin effective ivermectin drops for birds


2022/04/18 17:59:00

Wevgwongeさん

vet-vippsВ® accredited online pet pharmacy canadian drugs without prescription


2022/04/19 03:31:14

AnnoAudircurnさん

soft tabs viagra buy viagra uk


2022/04/20 04:23:01

Ennsexictさん

buy sildenafil generic canada cost of generic viagra in mexico


2022/04/20 11:24:33

nyyyplugsさん

levitra blindness levitra free


2022/04/20 14:52:53

Ahhpvunnyさん

where can i buy cialis over the counter cialis price costco


2022/04/21 08:55:33

Jnnyplugsさん

super active cialis with no prescription cialis ordering australia


2022/04/21 23:58:42

Wnsnwongeさん

levitra cost at rite aid levitra pill price


2022/04/22 09:57:00

AnuuAudircurnさん

Himplasia canadian drug pharmacy viagra


2022/04/23 08:47:05

Eaaqexictさん

best drugstore liquid eyeliner no prescription drugs


2022/04/23 15:47:44

Ntcxplugsさん

drug price pharmacy tech practice test online


2022/04/23 19:19:28

Ansnvunnyさん

canadian pharmacies that ship to usa Premarin


2022/04/24 13:14:47

Jmmplugsさん

mypharmacy canadian pharmacy british columbia


2022/04/25 04:55:53

Wnnhwongeさん

vyvanse canada pharmacy canadian pharmacies that accept credit cards


2022/04/25 14:44:12

JyhAudircurnさん

turkey pharmacy online peoples pharmacy austin store hours


2022/04/29 20:30:15

Ebbexictさん

Zestoretic how to stop calls from canadian pharmacy https://dtupharmyjn.com/


2022/04/30 03:16:17

Nndnplugsさん

alpesh pharmacy store charlotte nc top rated canadian online pharmacies https://jzpharmacyukj.com/


2022/04/30 06:47:26

Anbnvunnyさん

does sildenafil work for ed natural sildenafil citrate https://sildenafilkiol.com/


2022/05/01 00:14:46

Jebplugsさん

how to buy cheap viagra online sildenafil online purchase in india https://sgiviagraikn.com/


2022/05/01 15:24:06

Wnbhwongeさん

comprare levitra online levitra tablets https://glevitrargu.com/


2022/05/02 01:16:21

JyhgAudircurnさん

ivermectin paste for scabies ivermectin generic https://stromectolujlo.com/


2022/05/03 22:48:51

Ebbeexictさん

cialis online canada paypal buying cialis in australia https://dccialisxvf.com/


2022/05/04 05:19:03

Nndenplugsさん

levitra 20 mg wirkungsdauer levitra cautions https://xclevitradb.com/


2022/05/05 01:47:25

Jebnplugsさん

affordable pharmacy Motrin


2022/05/06 02:27:08

JolwAudircurnさん

order viagra soft tabs sildenafil 90mg https://aviagrasbt.com/


2022/05/09 16:56:27

Ebbeexictさん

cialis experience reddit how can i get cialis in australia https://dccialisxvf.com/


2022/05/09 23:12:29

Nndenplugsさん

how levitra works viagra vs cialis vs levitra reddit https://xclevitradb.com/


2022/05/10 02:40:31

Anbnvunnyさん

is viagra and sildenafil the same sildenafil other names https://sildenafilkiol.com/


2022/05/10 19:11:06

Jebnplugsさん

rx care pharmacy zephyrhills fl cheap prescription drugs


2022/05/11 10:00:04

Wnbhwongeさん

levitra daily dose levitra discount https://glevitrargu.com/


2022/05/11 20:08:54

JolwAudircurnさん

100mg sildenafil price female viagra pills in india https://aviagrasbt.com/


2022/05/14 12:46:59

EvaleenOaOaさん

nursing dissertation help
professional dissertation writers
write my dissertation uk help i can


2022/05/15 01:57:18

Nndenplugsさん

levitra 500 mg levitra how it works https://xclevitradb.com/


2022/05/15 05:23:54

Anbnvunnyさん

cipla sildenafil citrate sildenafil on empty stomach https://sildenafilkiol.com/


2022/05/15 07:48:20

MaggeeOaOaさん

example dissertation
online dissertation writing
dissertation writing uk


2022/05/15 22:35:50

Jebnplugsさん

erectile dysfunction medications Tofranil


2022/05/16 06:50:41

RegineOaOaさん

ford foundation dissertation fellowships
phd dissertation length
dissertation writing courses


2022/05/16 13:32:55

Wnbhwongeさん

levitra discounts side effects of levitra https://glevitrargu.com/


2022/05/18 00:52:07

povfpbaaさん

modafinil price


2022/05/18 10:47:08

scvuzwmnさん

purchase provigil pills modafinil 200mg cheap


2022/05/18 13:00:05

spxhejulさん

modafinil 200mg us order modafinil online


2022/05/18 22:22:53

Ebbeexictさん

how long does cialis last? orignal cialis https://dccialisxvf.com/


2022/05/19 01:00:12

ggpoyerkさん

buy erythromycin online erythromycin drug class


2022/05/19 05:07:33

Nndenplugsさん

levitra coupons where to buy levitra https://xclevitradb.com/


2022/05/19 07:39:02

vbzkkxlyさん

modafinil 100mg pills


2022/05/19 08:36:34

Anbnvunnyさん

sildenafil 10 mg is 20mg of sildenafil enough https://sildenafilkiol.com/


2022/05/19 18:41:47

wbjnxikmさん

purchase provigil online cheap


2022/05/19 19:27:24

KirstiOaOaさん

dissertation phd
buy a dissertation online help
doctoral dissertation help video


2022/05/19 23:15:47

zxzfjbgkさん

modafinil pills


2022/05/20 01:39:32

Jebnplugsさん

cialis 5mg canadian pharmacy pharmacy technician certification online


2022/05/20 07:01:25

fbwmmigqさん

how to use erythromycin ophthalmic ointment erythromycin spectrum


2022/05/20 09:27:57

dgeblzwsさん

order generic modafinil 100mg provigil ca provigil 200mg pills


2022/05/20 11:56:13

sthrnlaxさん

provigil 200mg price


2022/05/20 16:42:46

Wnbhwongeさん

prescription levitra levitra max dose https://glevitrargu.com/



コメントを投稿する


お名前


コメント内容





TOP back