GET & POST

Python

목록 보기
4/10

GET과 POST를 너무 막연하게만 알고있었다.
그래서 정보를 구글링했고, 찾은 블로그 링크
https://velog.io/@songyouhyun/Get%EA%B3%BC-Post%EC%9D%98-%EC%B0%A8%EC%9D%B4%EB%A5%BC-%EC%95%84%EC%8B%9C%EB%82%98%EC%9A%94

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

# POST 요청 API 예시코드
@app.route('/test', methods=['POST'])
def test_post():
   title_receive = request.form['title_give'] // post 의 경우 form['']
   print(title_receive)
   return jsonify({'result':'success', 'msg': '이 요청은 POST!'})
# GET 요청 확인 Ajax 예시코드
$.ajax({
    type: "GET",
    url: "/test?title_give=봄날은간다", // get은 데이터 전달 시에, url 뒤에 ?을 붙여 key=value로 전달
    data: {},
    success: function(response){
       console.log(response) }})
# POST 요청 확인 Ajax 예시코드
$.ajax({
    type: "POST",
    url: "/test",
    data: { title_give:'봄날은간다' }, // 바로 보이지 않는 html body에 key:value 형태로 전달
    success: function(response){
       console.log(response) }})

그리고, 미리 작성해 논 나의 네이버 블로그 포스팅
https://blog.naver.com/srlim26/222716681235

profile
백엔드를 공부하고 있습니다.

0개의 댓글