|
1 | 1 | ## Features
|
2 |
| -- #### Under active development! |
3 |
| -- #### Written in *Rust*, btw xD |
4 |
| -- #### A multithreaded Runtime |
5 |
| -- #### Extensible |
6 |
| -- #### A simple API |
7 |
| -- #### Sync and Async Function Support |
8 |
| -- #### Multithreaded file/directory serving |
9 |
| -- #### Dynamic URL Routing |
10 |
| -- #### Multi Core Scaling |
11 |
| -- #### Middlewares |
12 |
| -- #### WebSockets |
13 |
| -- #### Hot Reloading |
14 |
| -- #### Const Requests |
15 |
| -- #### Community First and truly FOSS! |
16 |
| -- #### Query Params |
17 |
| -- #### Events (Startup and Shutdown) |
| 2 | + |
| 3 | +### Synchronous API |
| 4 | +```python3 |
| 5 | + |
| 6 | +@app.get(‘/’) |
| 7 | +def h(): |
| 8 | + return “Hello, world†|
| 9 | +``` |
| 10 | + |
| 11 | +### Async API |
| 12 | + |
| 13 | +```python3 |
| 14 | +@app.get(‘/’) |
| 15 | +async def h(): |
| 16 | + return “Hello, world†|
| 17 | +``` |
| 18 | + |
| 19 | +### Directory Serving |
| 20 | + |
| 21 | +```python3 |
| 22 | +app.add_directory( |
| 23 | + route=â€/test_dirâ€, |
| 24 | + directory_path=â€/buildâ€, |
| 25 | + index_file=â€index.html†|
| 26 | +) |
| 27 | +``` |
| 28 | + |
| 29 | +### Static File Serving |
| 30 | + |
| 31 | +```python3 |
| 32 | +from Robyn import static_file |
| 33 | + |
| 34 | +@app.get(‘/’) |
| 35 | +async def test(): |
| 36 | + return static_file(“./index.htmlâ€) |
| 37 | +``` |
| 38 | + |
| 39 | +### URL Routing |
| 40 | + |
| 41 | +```python3 |
| 42 | +@app.get("/test/:test_file") |
| 43 | +async def test(request): |
| 44 | + test_file = request["params"]["test_file"] |
| 45 | + return static_file("./index.html") |
| 46 | +``` |
| 47 | + |
| 48 | +### Multi Core Scaling |
| 49 | + |
| 50 | +```python3 |
| 51 | +python3 app.py \ |
| 52 | + --processes=N \ |
| 53 | + --workers=N |
| 54 | +``` |
| 55 | + |
| 56 | +### Middlewares |
| 57 | + |
| 58 | +```python3 |
| 59 | +@app.before_request("/") |
| 60 | +async def hello_before_request(request): |
| 61 | + print(request) |
| 62 | + return "" |
| 63 | + |
| 64 | +@app.after_request("/") |
| 65 | +async def hello_after_request(request): |
| 66 | + print(request) |
| 67 | + return "" |
| 68 | +``` |
| 69 | + |
| 70 | + |
| 71 | +### WebSockets |
| 72 | + |
| 73 | +```python3 |
| 74 | +from robyn import WS |
| 75 | + |
| 76 | +websocket = WS(app, "/web_socket") |
| 77 | + |
| 78 | +@websocket.on("message") |
| 79 | +async def connect(websocket_id): |
| 80 | + return Òhow are youÓ |
| 81 | + |
| 82 | +@websocket.on("close") |
| 83 | +def close(): |
| 84 | + return "GoodBye world, from ws" |
| 85 | + |
| 86 | +@websocket.on("connect") |
| 87 | +async def message(): |
| 88 | + return "Hello world, from ws" |
| 89 | +``` |
| 90 | + |
| 91 | +### Const Requests |
| 92 | + |
| 93 | +```python3 |
| 94 | +@app.get(‘/’, const=True) |
| 95 | +async def h(): |
| 96 | + return “Hello, world†|
| 97 | +``` |
18 | 98 |
|
0 commit comments