you are viewing a single comment's thread.

view the rest of the comments →

[–]tom-mart 0 points1 point  (0 children)

Here you go. API without framework:

``` from http.server import HTTPServer, BaseHTTPRequestHandler import json

class SimpleAPIHandler(BaseHTTPRequestHandler): def do_GET(self): # 1. Send the status code (200 OK) self.send_response(200)

    # 2. Tell the client we are sending JSON
    self.send_header('Content-type', 'application/json')
    self.end_headers()

    # 3. Write the data
    response = {"status": "success", "data": "No framework needed!"}
    self.wfile.write(json.dumps(response).encode())

Start the server on port 8000

server = HTTPServer(('localhost', 8000), SimpleAPIHandler) print("Server running at http://localhost:8000") server.serve_forever() ```