본문 바로가기
개발일지

본격 API만들기

by 유안찡 2022. 11. 10.
<script>
    function hey() {
        $.ajax({
            type: "GET",
            url: "/test?title_give=봄날은간다",
            data: {},
            success: function (response) {
                console.log(response)
            }
        })
    }
</script>

 

 

url: "/test?title_give=봄날은간다",

/test라는 창구에 가는데 

title_give라는 이름으로 

봄날은 간다라는 데이터를 내가 갖고 갈게

 

 

 

url: "/test?주민등록번호=901234",

 

주민등록번호라는 이름으로 주민등록번호 숫자를 가져갈게

 

 

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

그리고 잘 된다면 너가 주는 데이터를 내가 console에다가 찍어볼게라는 뜻

 

 

 

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!'})

 

 

 

 

title_receive = request.args.get('title_give')

title_give라는 이름으로 뭔가를 받아와서 

그걸 title_receive(변수)에다 넣었고 

 

 

print(title_receive)

걔를 찍어줬어라는 뜻

 

 

 

@app.route('/test', methods=['GET'])

/test라는 창구에서 그것을 받고 있다

 

 

버튼을 클릭하면 

봄날은 간다를 가져갔고 

봄날은 간다를 가지고 와서 

걔를 찍었어요

그랬더니 찍혔다.