왕현성
코딩발자취
왕현성
전체 방문자
오늘
어제
  • 코딩 (277)
    • Python (71)
    • Java (16)
    • MySQL (34)
    • 인공지능 (48)
      • 머신러닝 (16)
      • 딥러닝 (32)
    • 영상처리 (4)
    • Rest API (21)
    • Android Studio (25)
    • streamlit (13)
    • DevOps (22)
      • AWS (9)
      • PuTTY (5)
      • Git (4)
      • Serverless (2)
      • Docker (2)
    • IT 기술 용어 (6)
    • 디버깅 ( 오류 해결 과정 ) (17)

블로그 메뉴

  • 홈
  • 태그
  • 방명록

공지사항

인기 글

태그

  • OpenCV
  • PYTHON
  • encoding='utf-8'
  • 의료이미징
  • matplotlib
  • pytorch
  • get_long_description
  • alibidetect
  • 영상처리역사
  • 기상탐사
  • labelme
  • ckpt_file
  • TensorFlow
  • maskimage
  • 영상처리
  • yolov8
  • numpy
  • 비지도학습
  • 컴퓨터비전
  • unsupervised
  • 영상기술
  • UnboundLocalError
  • labelme UnocodeDecodeError
  • alibi-detection
  • 딥러닝
  • tune()
  • PIL
  • pip install labelme
  • ComputerVision
  • imageprocessing

최근 댓글

최근 글

티스토리

250x250
hELLO · Designed By 정상우.
왕현성

코딩발자취

API서버 - 클라이언트가 원하는 값 삭제하기 (DELETE)
Rest API

API서버 - 클라이언트가 원하는 값 삭제하기 (DELETE)

2023. 1. 4. 17:39
728x90
from flask import Flask
from flask_restful import Api
from config import Config

from resources.recipe import RecipeListResource

app = Flask(__name__)
# 환경변수 셋팅
app.config.from_object(Config)

api = Api(app)

# 경로와 리소스(API코드)를 연결한다.
api.add_resource(RecipeListResource, '/recipes')

if __name__ == '__main__' :
    app.run()

메인 화면인 app.py의 코드는 이렇게 작성되어 있습니다.

 

DB의 값을 클라이언트로부터 원하는 값을 삭제하는 코드(delete)는 다음과 같습니다.

 

class RecipeResource(Resource) :

	def delete(self,recipe_id) :

        try :
            connection = get_connection()
            query = '''delete from recipe
                    where id = %s;'''
            record = (recipe_id,)

            cursor = connection.cursor()

            cursor.execute(query,record)

            connection.commit()

            cursor.close()
            connection.close()
        except Error as e :
            print(e)
            cursor.close()
            connection.close()
            return{'result':'fail','error':str(e)}, 500
        return {'result':'success'},200

포스트맨에서 확인.

MySQL에서 확인.

'Rest API' 카테고리의 다른 글

API - Flask_JWT 라이브러리 설치법과 사용법  (0) 2023.01.05
API - Postman 다운로드 , 사용법  (0) 2023.01.04
API서버 - 클라이언트에서 입력받은 값으로 DB 수정하기 (PUT)  (0) 2023.01.04
API - 클라이언트로부터 특정 정보의 값 출력하기 (GET)  (0) 2023.01.04
API - Python으로 DB에 값 넣기 (POST)  (0) 2023.01.04
    'Rest API' 카테고리의 다른 글
    • API - Flask_JWT 라이브러리 설치법과 사용법
    • API - Postman 다운로드 , 사용법
    • API서버 - 클라이언트에서 입력받은 값으로 DB 수정하기 (PUT)
    • API - 클라이언트로부터 특정 정보의 값 출력하기 (GET)
    왕현성
    왕현성
    AI 머신비전 학습일지

    티스토리툴바