[DAY7] CRUD

1nxeo·2023년 2월 12일

항해99

목록 보기
5/63
post-thumbnail

1. API

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

GET 요청 확인 Ajax 코드

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

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

POST 요청 확인 Ajax 코드

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

3. PUT

PUT 요청 API 코드

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

PUT 요청 확인 Ajax 코드

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

4. DELETE

DELETE 요청 API 코드

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

DELETE 요청 확인 Ajax 코드

$.ajax({
type: "POST",
url: "/test",
data: { title_give:'봄날은간다' },
success: function(response){
console.log(response)
}
})
profile
항상 피곤한 인서의 개발블로그

0개의 댓글