Skip to content

Commit 24e63ad

Browse files
committed
enhanced readme and app.py example
1 parent 94c46d7 commit 24e63ad

File tree

2 files changed

+66
-4
lines changed

2 files changed

+66
-4
lines changed

README.md

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,20 @@
33
## Description
44
Simple Web API controller framework for FastAPI
55

6+
## Installation
7+
8+
To install this package, use pip:
9+
10+
```bash
11+
pip install webapicontrollers
12+
```
13+
614
## Example
715
```python
816
from fastapi import FastAPI
9-
from webapicontrollers import APIController, Get, Post
17+
from webapicontrollers import APIController, Get, Post, Patch, Delete, Put, RoutePrefix
1018

19+
@RoutePrefix('/test')
1120
class TestController(APIController):
1221

1322
def __init__(self, app: FastAPI) -> None:
@@ -28,9 +37,38 @@ class TestController(APIController):
2837
@Post('/{arg}')
2938
async def post_with_arg(self, arg) -> dict:
3039
return {"method": "POST", "path": "/", "arg": arg}
40+
41+
@Put('/')
42+
async def put(self) -> dict:
43+
return {"method": "PUT", "path": "/"}
44+
45+
@Put('/{arg}')
46+
async def put_with_arg(self, arg) -> dict:
47+
return {"method": "PUT", "path": "/", "arg": arg}
48+
49+
@Patch('/')
50+
async def patch(self) -> dict:
51+
return {"method": "PATCH", "path": "/"}
52+
53+
@Patch('/{arg}')
54+
async def patch_with_arg(self, arg) -> dict:
55+
return {"method": "PATCH", "path": "/", "arg": arg}
56+
57+
@Delete('/')
58+
async def delete(self) -> dict:
59+
return {"method": "DELETE", "path": "/"}
60+
61+
@Delete('/{arg}')
62+
async def delete_with_arg(self, arg) -> dict:
63+
return {"method": "DELETE", "path": "/", "arg": arg}
64+
3165

3266
app = FastAPI()
3367
test_controller = TestController(app)
3468
```
3569
## Caution
36-
This project is in a very early state so far, doesn't do much and might not be very useful to anyone yet. There is no support avilable, use at your own risk
70+
This project is in a very early state and might not be very useful to anyone yet. There is no support avilable, use at your own risk.
71+
72+
## License
73+
74+
This project is licensed under the [MIT License](LICENSE).

src/app.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from fastapi import FastAPI
2-
from src.webapicontrollers import APIController, Get, Post, RoutePrefix
2+
from src.webapicontrollers import APIController, Get, Post, Patch, Delete, Put, RoutePrefix
33

44

5-
#@RoutePrefix('/test')
5+
@RoutePrefix('/test')
66
class TestController(APIController):
77

88
def __init__(self, app: FastAPI) -> None:
@@ -23,6 +23,30 @@ async def post(self) -> dict:
2323
@Post('/{arg}')
2424
async def post_with_arg(self, arg) -> dict:
2525
return {"method": "POST", "path": "/", "arg": arg}
26+
27+
@Put('/')
28+
async def put(self) -> dict:
29+
return {"method": "PUT", "path": "/"}
30+
31+
@Put('/{arg}')
32+
async def put_with_arg(self, arg) -> dict:
33+
return {"method": "PUT", "path": "/", "arg": arg}
34+
35+
@Patch('/')
36+
async def patch(self) -> dict:
37+
return {"method": "PATCH", "path": "/"}
38+
39+
@Patch('/{arg}')
40+
async def patch_with_arg(self, arg) -> dict:
41+
return {"method": "PATCH", "path": "/", "arg": arg}
42+
43+
@Delete('/')
44+
async def delete(self) -> dict:
45+
return {"method": "DELETE", "path": "/"}
46+
47+
@Delete('/{arg}')
48+
async def delete_with_arg(self, arg) -> dict:
49+
return {"method": "DELETE", "path": "/", "arg": arg}
2650

2751

2852
app = FastAPI()

0 commit comments

Comments
 (0)