Local Development Environment: My computer can be server and client at the same time

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/bf5b1c03-9f34-4202-bd5a-6dad881c6d1a/Untitled.png

# flask basic code
# app.py: server file

from flask import Flask
app = Flask(__name__)

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

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

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/0f1d1b75-006c-4eb8-9c99-f3925da4b582/Screen_Shot_2021-05-17_at_11.36.56_AM.png

When there is html file in templates directory, we can use render it in app.py with importing render_template.

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/03d75d00-e323-452a-ad29-946a3d75b571/Screen_Shot_2021-05-17_at_11.41.04_AM.png

API: a window server made to get client's request


GET

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

SERVER: in 127.0.0.1/5000/test page, if you "GET" something('title_give'), the variable title_receive will be the result. Send back my response {'result': 'success', 'msg': '이 요청은 GET!'} to client.

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

CLIENT: I'm gonna request "title_give=봄날은간다" to server. If i get success for some data, print response to console.