Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
Tags
- function
- 덴드로그램
- wcss
- len()
- elbow method
- pandas
- del
- matplotlib
- data
- 반복문
- numpy
- DataAccess
- string
- 최솟값
- hierarchical_clustering
- dendrogram
- Dictionary
- list
- DataFrame
- nan
- sklearn
- 최댓값
- analizer
- count()
- 분류 결과표
- Python
- insert()
- Machine Learning
- append()
- IN
Archives
- Today
- Total
개발공부
Python Flask에서 Resource 클래스를 이용한 API 서버 개발 방법 본문
Flask에서 Resource 클래스를 이용해 API 서버를 개발하는 틀의 예시는 아래와 같다.
app.py
from flask import Flask
from flask_restful import Api
from resources.recipe import RecipeListResource
from resources.recipe_info import RecipeResource
app = Flask(__name__)
api = Api(app)
# 경로와 리소스(API 코드)를 연결한다.
api.add_resource(RecipeListResource, '/recipes')
api.add_resource(RecipeResource, '/recipes/<int:recipe_id>')
if __name__ == '__main__' :
app.run()
recipe.py
from flask_restful import Resource
# Resource 클래스를 상속받아 사용한다.
class RecipeListResource(Resource) :
# restful api 의 method 에 해당하는 함수 작성
def post(self) :
pass
def get(self) :
pass
recipe_info.py
from flask_restful import Resource
# Resource 클래스를 상속받아 사용한다.
class RecipeResource(Resource) :
# 클라이언트로부터 /recipes/3 과 같은 식의 경로를 처리하므로
# 숫자는 바뀌므로, 변수로 처리해준다.
def get(self, recipe_id) :
pass
# 데이터를 업데이트하는 API들은 put 함수를 사용한다.
def put(self, recipe_id) :
pass
# 삭제하는 delete 함수
def delete(self, recipe_id) :
pass
'Python > Flask' 카테고리의 다른 글
| [Flask 에서 JWT 사용] 설치 방법 (0) | 2022.06.20 |
|---|---|
| Postman으로 API 테스트 방법 (0) | 2022.06.20 |
| Python MySQL Connector 를 이용해 Delete 하는 방법 (0) | 2022.06.17 |
| Python MySQL Connector 를 이용해 Update 하는 방법 (0) | 2022.06.17 |
| Python MySQL Connector 를 이용해 Select 하는 방법 (0) | 2022.06.17 |