Skip to content

Commit

Permalink
docs: restructure documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
sansyrox committed Aug 28, 2022
1 parent 9b06258 commit b12d098
Show file tree
Hide file tree
Showing 7 changed files with 299 additions and 19 deletions.
10 changes: 7 additions & 3 deletions docs/_sidebar.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
<!-- docs/_sidebar.md -->

- [Home](/)
- [Features](features.md)
- [API](api.md)
- [Installation](installation.md)
- [Getting Started](getting-started.md)
- [Community Resources](community-resources.md)
- [Examples](examples.md)
- [Feature Showcase](features.md)
- [Architecture](architecture.md)
- [Comparison](comparison.md)
- [Plugins](plugins.md)
- [API](api.md)
- [Future Roadmap](roadmap.md)
- [Plugins](plugins.md)
- [Sponsors](sponsors.md)

8 changes: 8 additions & 0 deletions docs/community-resources.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## Community Resources

### Talks

- [EuroPython 2022](https://www.youtube.com/watch?v=AutugvJNVkY&)
- [GeoPython 2022](https://www.youtube.com/watch?v=YCpbCQwbkd4)
- [PyCon US 2022](https://www.youtube.com/watch?v=1IiL31tUEVk)
- [PyCon Sweden 2021](https://www.youtube.com/watch?v=DK9teAs72Do)
105 changes: 105 additions & 0 deletions docs/examples.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
## Examples of Using Robyn

Below are a few examples of real life use cases of Robyn.

### Creating a Simple HTTP Service
```python3

from robyn import Robyn

app = Robyn(__file__)

@app.get("/")
async def h(request):
return "Hello, world!"

app.start(port=5000)

```

### Serving simple HTML Files
```python3

from robyn import Robyn, static_file

app = Robyn(__file__)

@app.get("/")
async def h(request):
return static_file("./index.html")

app.start(port=5000)

```


### Interaction with a Database

It should be fairly easy to make a crud app example. Here's a minimal example using Prisma(`pip install prisma-client-py`) with Robyn.

```py
from robyn import Robyn
from prisma import Prisma
from prisma.models import User

app = Robyn(__file__)
prisma = Prisma(auto_register=True)

@app.startup_handler
async def startup_handler() -> None:
await prisma.connect()

@app.shutdown_handler
async def shutdown_handler() -> None:
if prisma.is_connected():
await prisma.disconnect()

@app.get("/")
async def h():
user = await User.prisma().create(
data={
"name": "Robert",
},
)
return user.json(indent=2)

app.start(port=5000)
```

Using this Prisma Schema:

```prisma
datasource db {
provider = "sqlite"
url = "file:dev.db"
}
generator py {
provider = "prisma-client-py"
}
model User {
id String @id @default(cuid())
name String
}
```

### Using Middleware
```python3

from robyn import Robyn, static_file

app = Robyn(__file__)

@app.get("/")
async def h(request):
return static_file("./index.html")

app.start(port=5000)

```
### A basic web socket chat app.
Coming Soon....

### Using Robyn to send an email
Coming Soon....
112 changes: 96 additions & 16 deletions docs/features.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,98 @@
## Features
- #### Under active development!
- #### Written in *Rust*, btw xD
- #### A multithreaded Runtime
- #### Extensible
- #### A simple API
- #### Sync and Async Function Support
- #### Multithreaded file/directory serving
- #### Dynamic URL Routing
- #### Multi Core Scaling
- #### Middlewares
- #### WebSockets
- #### Hot Reloading
- #### Const Requests
- #### Community First and truly FOSS!
- #### Query Params
- #### Events (Startup and Shutdown)

### Synchronous API
```python3

@app.get(‘/’)
def h():
return “Hello, world”
```

### Async API

```python3
@app.get(‘/’)
async def h():
return “Hello, world”
```

### Directory Serving

```python3
app.add_directory(
route=”/test_dir”,
directory_path=”/build”,
index_file=”index.html”
)
```

### Static File Serving

```python3
from Robyn import static_file

@app.get(‘/’)
async def test():
return static_file(“./index.html”)
```

### URL Routing

```python3
@app.get("/test/:test_file")
async def test(request):
test_file = request["params"]["test_file"]
return static_file("./index.html")
```

### Multi Core Scaling

```python3
python3 app.py \
--processes=N \
--workers=N
```

### Middlewares

```python3
@app.before_request("/")
async def hello_before_request(request):
print(request)
return ""

@app.after_request("/")
async def hello_after_request(request):
print(request)
return ""
```


### WebSockets

```python3
from robyn import WS

websocket = WS(app, "/web_socket")

@websocket.on("message")
async def connect(websocket_id):
return Òhow are youÓ

@websocket.on("close")
def close():
return "GoodBye world, from ws"

@websocket.on("connect")
async def message():
return "Hello world, from ws"
```

### Const Requests

```python3
@app.get(‘/’, const=True)
async def h():
return “Hello, world”
```

69 changes: 69 additions & 0 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
## Getting Started.

We will go through the process of creating a "Hello, World!" app.

### Step 1: Creating a virtualenv

To ensure that there are isolated dependencies, we will use virtualenvironments.

```
python3 -m venv venv
```

### Step 2: Activate the virtualenv and install Robyn

#### Activating the virtualenv
```
source venv/bin/activate
```

#### Installing Robyn
```
pip install robyn
```

### Step 3: Creating the App.

- Create a file called `app.py`.

- In your favourite editor, open `app.py` and write the following.

```python

from robyn import Robyn

app = Robyn(__file__)

@app.get("/")
async def h():
return "Hello, world!"

app.start(port=5000, url="0.0.0.0") # url is optional, defaults to 127.0.0.1

```

Let us try to decipher the usage line by line.

> from robyn import Robyn
This statement just imports the Robyn structure from the robyn package.

> app = Robyn(__file__)
Here, we are creating the app object. We require the `__file__` object to mount the directory for hot reloading.

### Step 4. Running the service

You can just use the command

```
python3 app.py
```

if you want to run the production version, and

```
python3 app.py --dev=true
```
if you want to enable hot reloading or the development version.

13 changes: 13 additions & 0 deletions docs/installation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## 📦 Installation

You can simply use Pip for installation.

```
pip install robyn
```

Or, with [conda-forge](https://conda-forge.org/)

```
conda install -c conda-forge robyn
```
1 change: 1 addition & 0 deletions docs/usage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
##

0 comments on commit b12d098

Please sign in to comment.