-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.py
More file actions
27 lines (21 loc) · 675 Bytes
/
api.py
File metadata and controls
27 lines (21 loc) · 675 Bytes
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
from http.server import BaseHTTPRequestHandler, HTTPServer
import json
HOST = "localhost"
PORT = 8000
class Server(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.send_header("Content-Type", "application/json")
self.end_headers()
response = json.dumps({
"message": "Success!"
})
self.wfile.write(bytes(response, "utf-8"))
if __name__ == "__main__":
server = HTTPServer((HOST, PORT), Server)
print(f"Server started @ http://{HOST}:{PORT}")
try:
server.serve_forever()
except KeyboardInterrupt:
server.server_close()
print("\nServer stopped.")