**GET

→ 통상적으로! 데이터 조회(Read)를 요청할 때

예) 영화 목록 조회

데이터 전달 : URL 뒤에 물음표를 붙여 key=value로 전달

→ 예: google.com?q=북극곰 

 

**POST

→ 통상적으로! 데이터 생성(Create), 변경(Update), 삭제(Delete) 요청 할 때

예) 회원가입, 회원탈퇴, 비밀번호 수정

데이터 전달 : 바로 보이지 않는 HTML body에 key:value 형태로 전달

 

 

 

GET 요청 API코드 (Python)

@app.route('/test', methods=['GET'])
def test_get():
   title_receive = request.args.get('title_give')
   print(title_receive)
   return jsonify({'result':'success', 'msg': '이 요청은 GET!'})

GET 요청 확인 Ajax코드(javescript)

$.ajax({
    type: "GET",
    url: "/test?title_give=봄날은간다",
    data: {},
    success: function(response){
       console.log(response)
    }
  })

> localhost:5000 접속 후 F12 눌러서 콘솔창에서 확인

 

 

 

POST 요청 API코드 (Python)

@app.route('/test', methods=['POST'])
def test_post():
   title_receive = request.form['title_give']
   print(title_receive)
   return jsonify({'result':'success', 'msg': '이 요청은 POST!'})

 

POST 요청 확인 Ajax코드(javescript)

$.ajax({
    type: "POST",
    url: "/test",
    data: { title_give:'봄날은간다' },
    success: function(response){
       console.log(response)
    }
  })

 

 

 

'Coding' 카테고리의 다른 글

Python Flask 설치  (0) 2022.06.29
파이썬 웹 크롤링  (0) 2022.06.29

+ Recent posts