NEW: Fenrir v1.2.2 is now available — Logo & Favicon Patch! Read the changelog
class-based-resources.md
docs class-based-resources.md

Class-Based Resources

Falcon-style resources for organized code:

 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
from fenrir import View

# Basic resource with HTTP methods
class ItemResource:
    async def on_get(self, req, resp, item_id: int):
        """Get item"""
        resp.status = 200
        resp.media = {
            "item_id": item_id,
            "name": f"Item {item_id}",
            "status": "active"
        }

    async def on_post(self, req, resp, item_id: int):
        """Create or update item"""
        data = req.json  # Parsed JSON body
        resp.status = 201
        resp.media = {
            "item_id": item_id,
            "data": data,
            "created": True
        }

    async def on_delete(self, req, resp, item_id: int):
        """Delete item"""
        resp.status = 204

# Register resource
app.add_route("/items/<item_id:int>", ItemResource())

Class-Based Views

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
from fenrir import MethodView, request

class ItemListView(MethodView):
    async def get(self):
        """List all items"""
        return [{"id": 1, "name": "Item 1"}]

    async def post(self):
        """Create new item"""
        data = request.json
        return {"id": 2, "name": data["name"], "created": True}

app.add_route("/items", ItemListView())
Edit on GitHub Last Updated: Jun 04, 2026
© 2026 Fenrir Project.
main*
v1.2.2
Ln 1, Col 1
UTF-8
Prettier
Light Mode
Markdown