diff --git a/examples/hello_world/app.py b/examples/hello_world/app.py index 7891afb..24708f5 100644 --- a/examples/hello_world/app.py +++ b/examples/hello_world/app.py @@ -1,20 +1,23 @@ # examples/hello_world/app.py -from haske import Haske, Request, Response +from haske import Haske, Request app = Haske(__name__) +data = [{"id": 1, "name": "Alice"}, {"id": 2, "name": "Bob"}] + @app.route("/") async def homepage(request: Request): return {"message": "Hello, Haske!", "version": "0.1.0"} @app.route("/api/users", methods=["GET"]) async def get_users(request: Request): - return {"users": [{"id": 1, "name": "Alice"}, {"id": 2, "name": "Bob"}]} + return data -@app.route("/api/users/:id", methods=["GET"]) +@app.route("/api/user/{id}", methods=["GET"]) async def get_user(request: Request): - user_id = request.get_path_param("id") - return {"id": user_id, "name": f"User {user_id}"} + user_id = request.path_params.get("id") + user = next((user for user in data if user["id"] == int(user_id)), None) + return user if __name__ == "__main__": app.run(host="0.0.0.0", port=8000, debug=True) \ No newline at end of file diff --git a/haske-python/haske/__pycache__/app.cpython-312.pyc b/haske-python/haske/__pycache__/app.cpython-312.pyc index ab6ba92..4d5f0d7 100644 Binary files a/haske-python/haske/__pycache__/app.cpython-312.pyc and b/haske-python/haske/__pycache__/app.cpython-312.pyc differ diff --git a/haske-python/haske/app.py b/haske-python/haske/app.py index 327cef7..f84c09e 100644 --- a/haske-python/haske/app.py +++ b/haske-python/haske/app.py @@ -152,7 +152,7 @@ def mount(self, path: str, app: Any, name: str = None): """ self.routes.append(Mount(path, app=app, name=name)) - def static(self, path: str, directory: str, name: str = None): + def static(self, path: str = "/static", directory: str = "static", name: str = None): """ Serve static files from a directory.