Skip to content

Commit

Permalink
docs: fix syntax highlighting in code samples
Browse files Browse the repository at this point in the history
  • Loading branch information
sansyrox committed Sep 3, 2022
1 parent 532bce6 commit 388f505
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 24 deletions.
1 change: 1 addition & 0 deletions docs/_sidebar.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- [Comparison](comparison.md)
- [API](api.md)
- [Community Resources](community-resources.md)
- [GraphQL Support](graphql-integration.md)
- [Future Roadmap](roadmap.md)
- [Plugins](plugins.md)
- [Hosting](hosting.md)
Expand Down
9 changes: 5 additions & 4 deletions docs/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Below are a few examples of real life use cases of Robyn.

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

from robyn import Robyn

Expand All @@ -18,7 +18,7 @@ app.start(port=5000)
```

### Serving simple HTML Files
```python3
```python

from robyn import Robyn, static_file

Expand All @@ -37,7 +37,7 @@ app.start(port=5000)

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
```python
from robyn import Robyn
from prisma import Prisma
from prisma.models import User
Expand Down Expand Up @@ -85,7 +85,7 @@ model User {
```

### Using Middleware
```python3
```python

from robyn import Robyn, static_file

Expand All @@ -98,6 +98,7 @@ async def h(request):
app.start(port=5000)

```

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

Expand Down
38 changes: 19 additions & 19 deletions docs/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
## Synchronous Requests
Robyn supports both sync methods and async methods for fetching requests. Every method gets a request object from the routing decorator.

```python3
```python

@app.get("/")
def h(request):
Expand All @@ -13,7 +13,7 @@ def h(request):

## Async Requests

```python3
```python
@app.get("/")
async def h(request):
return "Hello, world"
Expand All @@ -28,23 +28,23 @@ Robyn supports every HTTP request method. The examples of some of them are below

#### GET Request

```python3
```python
@app.get("/")
async def h(request):
return "Hello World"
```

#### POST Request

```python3
```python
@app.post("/post")
async def postreq(request):
return bytearray(request["body"]).decode("utf-8")
```

#### PUT Request

```python3
```python
@app.put("/put")
async def postreq(request):
return bytearray(request["body"]).decode("utf-8")
Expand All @@ -53,7 +53,7 @@ async def postreq(request):

#### PATCH Request

```python3
```python
@app.patch("/patch")
async def postreq(request):
return bytearray(request["body"]).decode("utf-8")
Expand All @@ -62,7 +62,7 @@ async def postreq(request):

#### DELETE Request

```python3
```python
@app.delete("/delete")
async def postreq(request):
return bytearray(request["body"]).decode("utf-8")
Expand All @@ -71,7 +71,7 @@ async def postreq(request):

#### Directory Serving

```python3
```python
app.add_directory(
route="/test_dir"
directory_path="/build"
Expand All @@ -82,7 +82,7 @@ app.add_directory(
## Dynamic Routes
You can add params in the routes and access them from the request object.

```python3
```python
@app.post("/jsonify/:id")
async def json(request):
print(request["params"]["id"])
Expand All @@ -92,7 +92,7 @@ async def json(request):
## Returning a JSON Response
You can also serve JSON responses when serving HTTP request using the following way.

```python3
```python
from robyn import jsonify

@app.post("/jsonify")
Expand All @@ -104,7 +104,7 @@ async def json(request):
## Global Headers
You can also add global headers for every request.

```python3
```python
app.add_header("server", "robyn")

```
Expand All @@ -118,7 +118,7 @@ For the url: `http://localhost:5000/query?a=b`

You can use the following code snippet.

```python3
```python
@app.get("/query")
async def query_get(request):
query_data = request["queries"]
Expand All @@ -130,7 +130,7 @@ async def query_get(request):

You can add startup and shutdown events in robyn. These events will execute before the requests have started serving and after the serving has been completed.

```python3
```python

async def startup_handler():
print("Starting up")
Expand All @@ -148,7 +148,7 @@ You can now serve websockets using Robyn.

Firstly, you need to create a WebSocket Class and wrap it around your Robyn app.

```python3
```python
from robyn import Robyn, static_file, jsonify, WS


Expand All @@ -158,7 +158,7 @@ websocket = WS(app, "/web_socket")

Now, you can define 3 methods for every web_socket for their life cycle, they are as follows:

```python3
```python
@websocket.on("message")
def connect():
global i
Expand Down Expand Up @@ -193,7 +193,7 @@ To see a complete service in action, you can go to the folder [../integration_te

#### Web Socket Usage

```python3
```python
@websocket.on("message")
async def connect():
global i
Expand Down Expand Up @@ -222,7 +222,7 @@ async def message():

You can use both sync and async functions for middlewares!

```python3
```python
@app.before_request("/")
async def hello_before_request(request):
print(request)
Expand All @@ -237,15 +237,15 @@ def hello_after_request(request):

To run Robyn across multiple cores, you can use the following command:

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



## Const Requests

You can pre-compute the response for each route. This will compute the response even before execution. This will improve the response time bypassing the need to access the router.

```python3
```python
@app.get("/", const=True)
async def h():
return "Hello, world"
Expand Down
3 changes: 2 additions & 1 deletion docs/graphql-integration.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## GraphQl Support (with <a target="_blank" href="https://strawberry.rocks/">Strawberry 🍓</a>)
## GraphQl Support (<a target="_blank" href="https://strawberry.rocks/">with Strawberry 🍓</a>)

<i>This is in a very early stage right now. We will have a much more stable version when we have a stable API for Views and View Controllers.</i>

Expand Down Expand Up @@ -164,5 +164,6 @@ async def post(request):
```
Finally, we are getting params(body, query, variables, context_value, root_value, operation_name) from the `request` object.

The above is the example for just one route. You can do the same for as many as you like. :)

That's all folks. :D

0 comments on commit 388f505

Please sign in to comment.