**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

1. PyCharm 2022.1.1 설치

2. prac 폴더 생성

3. prac 폴더에 app.py 파일 생성(prac 우클릭 > python file)
(통상적으로 flask 서버를 돌리는 파일은 app.py라고 이름 지음)

 

4. PyCharm 에서 Flask 설치하기

윈도우 : 좌상단File → setting → Python interpreter

맥 : 좌상단Pycharm → Preference → Python Interpreter

 

flask 검색 후 좌측 하단에 Install Package 클릭 > 설치 끝난 후 > x 눌러서 창 off > OK 

 

🔽플라스크(flask) 시작 코드

from flask import Flask
app = Flask(__name__)

@app.route('/')
def home():
   return 'This is Home!'

if __name__ == '__main__':
   app.run('0.0.0.0',port=5000,debug=True)

Run 눌러주기

그 후 크롬 창에

localhost:5000 검색 (❌ localhost5000 아님! : 를 넣어야함(오타주의))

This is Home! 이 나오면 설치 성공

 

 

flask 프레임워크 설치 끝

'Coding' 카테고리의 다른 글

Flask시작하기 - 본격 API 만들기(Get, Post 요청코드)  (0) 2022.07.03
파이썬 웹 크롤링  (0) 2022.06.29
import requests
from bs4 import BeautifulSoup

headers = {'User-Agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36'}
data = requests.get('https://www.genie.co.kr/chart/top200',headers=headers)

soup = BeautifulSoup(data.text, 'html.parser')

 

파이썬 크롤링 기본 코드

 

'Coding' 카테고리의 다른 글

Flask시작하기 - 본격 API 만들기(Get, Post 요청코드)  (0) 2022.07.03
Python Flask 설치  (0) 2022.06.29

+ Recent posts