**BREAKING CHANGE** renamed `Server` class to `App`

Commit a406c2c · patx · 2025-02-02T23:48:23-05:00

Changeset
a406c2c8f92f9bff3a06f932dcaad26801814195
Parents
2531e7ac2f57eb550b6d724b6a20f87d3f5b62bd

View source at this commit

Comments

No comments yet.

Log in to comment

Diff

diff --git a/MicroPie.py b/MicroPie.py
index a16899a..03c4497 100644
--- a/MicroPie.py
+++ b/MicroPie.py
@@ -78,13 +78,13 @@ class Request:
         self.files: Dict[str, Any] = {}
 
 
-class Server:
-    """ASGI server for handling HTTP requests and WebSocket connections in MicroPie."""
+class App:
+    """ASGI application for handling HTTP requests and WebSocket connections in MicroPie."""
     SESSION_TIMEOUT: int = 8 * 3600
 
     def __init__(self) -> None:
         """
-        Initialize a new Server instance.
+        Initialize a new App instance.
 
         If Jinja2 is installed, set up the template environment.
         """
diff --git a/README.md b/README.md
index 080b07a..6236678 100644
--- a/README.md
+++ b/README.md
@@ -43,9 +43,9 @@ pip install uvicorn
 
 Save the following as `app.py`:
 ```python
-from MicroPie import Server
+from MicroPie import App
 
-class MyApp(Server):
+class MyApp(App):
     async def index(self):
         return "Welcome to MicroPie ASGI."
 
@@ -60,11 +60,11 @@ Access your app at [http://127.0.0.1:8000](http://127.0.0.1:8000).
 ## **Core Features**
 
 ### **1. Flexible HTTP Routing for GET Requests**
-MicroPie automatically maps URLs to methods within your `Server` class. Routes can be defined as either synchronous or asynchronous functions, offering good flexibility.
+MicroPie automatically maps URLs to methods within your `App` class. Routes can be defined as either synchronous or asynchronous functions, offering good flexibility.
 
 For GET requests, pass data through query strings or URL path segments, automatically mapped to method arguments.
 ```python
-class MyApp(Server):
+class MyApp(App):
     async def greet(self, name="Guest"):
         return f"Hello, {name}!"
 
@@ -79,7 +79,7 @@ class MyApp(Server):
 ### **2. Flexible HTTP POST Request Handling**
 MicroPie also supports handling form data submitted via HTTP POST requests. Form data is automatically mapped to method arguments. It is able to handle default values and raw POST data:
 ```python
-class MyApp(Server):
+class MyApp(App):
     async def submit_default_values(self, username="Anonymous"):
         return f"Form submitted by: {username}"
 
@@ -98,7 +98,7 @@ Dynamic HTML generation is supported via Jinja2. This happens asynchronously usi
 
 #### **`app.py`**
 ```python
-class MyApp(Server):
+class MyApp(App):
     async def index(self):
         return await self._render_template("index.html", title="Welcome", message="Hello from MicroPie!")
 ```
@@ -125,7 +125,7 @@ Here again, like Websockets, MiroPie does not have a built in static file method
 Support for streaming responses makes it easy to send data in chunks.
 
 ```python
-class MyApp(Server):
+class MyApp(App):
     async def stream(self):
         async def generator():
             for i in range(1, 6):
@@ -137,7 +137,7 @@ class MyApp(Server):
 Built-in session handling simplifies state management:
 
 ```python
-class MyApp(Server):
+class MyApp(App):
     async def index(self):
         if "visits" not in self.session:
             self.request.session["visits"] = 1
@@ -147,7 +147,7 @@ class MyApp(Server):
 ```
 
 ### **8. Deployment**
-MicroPie apps can be deployed using any ASGI server. For example, using Uvicorn if our application is saved as `app.py` and our `Server` subclass is assigned to the `app` variable we can run it with:
+MicroPie apps can be deployed using any ASGI server. For example, using Uvicorn if our application is saved as `app.py` and our `App` subclass is assigned to the `app` variable we can run it with:
 ```bash
 uvicorn app:app --workers 4 --port 8000
 ```
diff --git a/docs/api.html b/docs/api.html
index 0d905f1..9aad121 100644
--- a/docs/api.html
+++ b/docs/api.html
@@ -27,9 +27,9 @@
         <li><strong>files</strong>: Uploaded files in the request.</li>
     </ul>
 
-    <h2>Server Class</h2>
-    <p>ASGI server for handling HTTP requests and WebSocket connections.</p>
-    <pre><code>class Server()</code></pre>
+    <h2>App Class</h2>
+    <p>ASGI application framework for handling HTTP requests.</p>
+    <pre><code>class App()</code></pre>
 
     <h3>Properties</h3>
     <ul>
diff --git a/docs/index.html b/docs/index.html
index bb5db6a..e3b1df5 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -112,9 +112,9 @@
 
         <h2>MicroPie is Fun</h2>
         <pre><code>
-<span class="c2">from</span> MicroPie <span class="c2">import</span> Server
+<span class="c2">from</span> MicroPie <span class="c2">import</span> App
 
-<span class="c2">class</span> MyApp(<span class="c9">Server</span>):
+<span class="c2">class</span> MyApp(<span class="c9">App</span>):
 
     <span class="c2">async def</span> index(<span class="c9">self</span>):
         return <span class="c9">'Hello World!'</span>
diff --git a/examples/file_uploads/app.py b/examples/file_uploads/app.py
index e4c9569..6237fb0 100644
--- a/examples/file_uploads/app.py
+++ b/examples/file_uploads/app.py
@@ -1,4 +1,4 @@
-from MicroPie import Server
+from MicroPie import App
 
 import os
 from typing import Any
@@ -6,7 +6,7 @@ from typing import Any
 UPLOAD_DIR = "uploads"
 os.makedirs(UPLOAD_DIR, exist_ok=True)  # Ensure upload directory exists
 
-class FileUploadApp(Server):
+class FileUploadApp(App):
 
     async def index(self):
         """Serves an HTML form for file uploads."""
diff --git a/examples/headers/app.py b/examples/headers/app.py
index 38e3ce9..775a884 100644
--- a/examples/headers/app.py
+++ b/examples/headers/app.py
@@ -1,7 +1,7 @@
-from MicroPie import Server
+from MicroPie import App
 
 
-class Root(Server):
+class Root(App):
     def index(self):
         headers = [
             ("Content-Type", "text/html"),
diff --git a/examples/hello_world/app.py b/examples/hello_world/app.py
index 19a739e..0a1bfc1 100644
--- a/examples/hello_world/app.py
+++ b/examples/hello_world/app.py
@@ -1,7 +1,7 @@
-from MicroPie import Server
+from MicroPie import App
 
 
-class Root(Server):
+class Root(App):
 
     async def index(self):
         return 'Hello ASGI World!'
diff --git a/examples/pastebin/app.py b/examples/pastebin/app.py
index bf133d9..a458242 100644
--- a/examples/pastebin/app.py
+++ b/examples/pastebin/app.py
@@ -5,13 +5,13 @@ A simple no frills pastebin using MicroPie, pickleDB, and highlight.js.
 
 from uuid import uuid4
 
-from MicroPie import Server
+from MicroPie import App
 from pickledb import PickleDB
 from markupsafe import escape
 
 db = PickleDB('pastes.db')
 
-class Root(Server):
+class Root(App):
 
     async def index(self):
         if self.request.method == "POST":
diff --git a/examples/requests/app.py b/examples/requests/app.py
index 651cd32..2698eba 100644
--- a/examples/requests/app.py
+++ b/examples/requests/app.py
@@ -1,4 +1,4 @@
-from MicroPie import Server
+from MicroPie import App
 
 # Request handlers defined outside the class
 
@@ -28,7 +28,7 @@ def options_handler():
     ]
 
 # Define the custom server application
-class Root(Server):
+class Root(App):
 
     # Handle root URL requests and delegate based on HTTP method
     def index(self):
diff --git a/examples/socketio/chatroom.py b/examples/socketio/chatroom.py
index c660578..d22672c 100644
--- a/examples/socketio/chatroom.py
+++ b/examples/socketio/chatroom.py
@@ -1,11 +1,11 @@
 import socketio
-from MicroPie import Server
+from MicroPie import App
 
 # Create a Socket.IO server with CORS support
 sio = socketio.AsyncServer(async_mode="asgi", cors_allowed_origins="*")  # Allow all origins
 
 # Create the MicroPie server
-class MyApp(Server):
+class MyApp(App):
     async def index(self):
         return await self._render_template("chat.html")
 
diff --git a/examples/socketio/webcam.py b/examples/socketio/webcam.py
index 65e7e86..15ff524 100644
--- a/examples/socketio/webcam.py
+++ b/examples/socketio/webcam.py
@@ -1,5 +1,5 @@
 import socketio
-from MicroPie import Server
+from MicroPie import App
 
 # Create the Socket.IO server
 sio = socketio.AsyncServer(async_mode="asgi")
@@ -8,7 +8,7 @@ sio = socketio.AsyncServer(async_mode="asgi")
 active_users = set()
 
 # MicroPie Server with integrated Socket.IO
-class MyApp(Server):
+class MyApp(App):
     async def index(self):
         return await self.render_template("index_stream.html")
 
diff --git a/examples/socketio/webtrc/app.py b/examples/socketio/webtrc/app.py
index 4456f09..ce18974 100644
--- a/examples/socketio/webtrc/app.py
+++ b/examples/socketio/webtrc/app.py
@@ -1,5 +1,5 @@
 import socketio
-from MicroPie import Server
+from MicroPie import App
 
 # 1) Create the Async Socket.IO server and wrap with an ASGI app.
 sio = socketio.AsyncServer(async_mode="asgi")
@@ -8,7 +8,7 @@ sio = socketio.AsyncServer(async_mode="asgi")
 active_users = set()
 
 # 2) Create a MicroPie server class with routes
-class MyApp(Server):
+class MyApp(App):
     async def index(self):
         # A simple response for the root path
         return 'Use /stream/*username* or /watch/*username*'
diff --git a/examples/static_content/app.py b/examples/static_content/app.py
index d28b8d3..ff84e61 100644
--- a/examples/static_content/app.py
+++ b/examples/static_content/app.py
@@ -1,7 +1,7 @@
 from servestatic import ServeStaticASGI
-from MicroPie import Server
+from MicroPie import App
 
-class Root(Server):
+class Root(App):
     async def index(self):
         return "Hello, World!"
 
diff --git a/examples/streaming/text.py b/examples/streaming/text.py
index a748598..28779af 100644
--- a/examples/streaming/text.py
+++ b/examples/streaming/text.py
@@ -1,8 +1,8 @@
 import time
 import asyncio
-from MicroPie import Server
+from MicroPie import App
 
-class Root(Server):
+class Root(App):
 
     def index(self):
         # Normal, immediate response (non-streaming)
diff --git a/examples/streaming/video.py b/examples/streaming/video.py
index e72fe81..1038de2 100644
--- a/examples/streaming/video.py
+++ b/examples/streaming/video.py
@@ -1,9 +1,9 @@
 import os
-from MicroPie import Server
+from MicroPie import App
 
 VIDEO_PATH = "video.mp4"
 
-class Root(Server):
+class Root(App):
     def index(self):
         return '''
             <html>
diff --git a/examples/twutr/twutr.py b/examples/twutr/twutr.py
index 7e60afd..63b5031 100644
--- a/examples/twutr/twutr.py
+++ b/examples/twutr/twutr.py
@@ -7,7 +7,7 @@
 from datetime import datetime
 import re
 
-from MicroPie import Server
+from MicroPie import App
 from pickledb import PickleDB
 from markupsafe import escape
 
@@ -141,7 +141,7 @@ def convert_custom_syntax(text):
 # ----------------
 
 
-class Twutr(Server):
+class Twutr(App):
     """
     Main application class for handling routes.
     The helper functions above are outside the class,