-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.py
41 lines (30 loc) · 845 Bytes
/
api.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env python
from flask import Flask, jsonify
app = Flask('MyApp')
server_bind = '0.0.0.0'
server_port = 12345
max_connections = 1000
# SSL/TLS params (recommended, but optional)
ssl_certificate = None
ssl_key = None
@app.route('/hello/<string:name>', methods=['GET'])
def hello(name):
"""
************************
* Write your API here! *
************************
"""
return jsonify('hello {}!'.format(name))
if __name__ == '__main__':
from gevent.pywsgi import WSGIServer
config = {
'listener': (server_bind, server_port),
'application': app,
'spawn': max_connections,
}
if ssl_certificate:
config['certfile'] = ssl_certificate
if ssl_key:
config['keyfile'] = ssl_key
http_server = WSGIServer(**config)
http_server.serve_forever()