I had the opportunity to create a web application from scratch with Python, so as a summary! This article describes how to do Hello World with API.
The goal is to create a web app with CURD functionality using HTML, CSS, JavaScript, Python, and SQL.
The folders and files created this time are as follows.
todo/ └ api/ └ index.py
The features of each framework are for reference below.
Open a command prompt as an administrator and execute the following command. Only this.
pip install bottle
Create a working folder and open it with VS Code. Then, create the following folders and files. (.vscode is generated by VS Code without permission) todo/ └ api/ └ index.py
Then write the code in index.py.
index.py
# -*- coding:utf-8 -*-
#Load an external package
from bottle import route, run
# @to route/If set to hello, http://localhost:8080/Can be accessed with hello
@route('/hello')
def hello():
# Hello World!Returns the string
return "Hello World!"
#Web server execution configuration
#URL"http://[host]:[port]/[route]"Becomes the composition of
run(host='localhost', port=8080, debug=True)
Press F5 and select Python File.
http://localhost:8080/hello When you visit, you should see "Hello World!"!
As the first step of API implementation, I tried Hello World!
Connect to the database from the API!
Recommended Posts