GET = 통상적으로 테이터 조회를 요청할때

URL 뒤에 물을표를 붙여 KEY=VALUE로 전달

예) google.con?q=북극곰

 

POST = 통상적으로 데이터 생성, 변경, 삭제요청을 할때

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

 

api만들기

 

GET

get요청 api 코드

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

get요청 확인 ajax코드(콘솔창에 입력)

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

 

response = 서버에서 내려주는 값

 

"title_give로 갖고온거 값 가져와봐"라는 뜻 통째로 이해

 

POST

post 요청 api 코드

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

 

post 요청 확인 ajax코드

 

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

get의 title_giv로 가지고 온 값 한번 여기다가 찍어줘바랑 같은 역할

※internal server error = 서버쪽에 에러가 났다는 뜻

'로컬개발환경 > flask' 카테고리의 다른 글

flask시작하기-서버만들기  (0) 2022.06.12
api설계하기  (0) 2022.06.07
api 만들기 (get연습)  (0) 2022.06.07
html파일 주기  (0) 2022.06.03
flask  (0) 2022.05.31

+ Recent posts