Skip to content

Commit

Permalink
docs: Add docs for v0.26.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sansyrox committed Apr 1, 2023
1 parent 3ef0cdb commit 0c00a06
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 13 deletions.
48 changes: 37 additions & 11 deletions docs/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,31 +37,31 @@ async def h(request):
```python
@app.post("/post")
async def postreq(request):
return bytearray(request["body"]).decode("utf-8")
return request.body
```

#### PUT Request

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

#### PATCH Request

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

#### DELETE Request

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

#### Directory Serving
Expand Down Expand Up @@ -133,6 +133,20 @@ async def response(request):
return Response(status_code=200, headers={}, body="OK")
```

#### Status Codes

Robyn provides `StatusCodes` if you want to return type safe Status Responses.

```python

from robyn import StatusCodes


@app.get("/response")
async def response(request):
return Response(status_code=StatusCodes.HTTP_200_OK.value, headers={}, body="OK")
```

#### Returning a byte response
You can also return byte response when serving HTTP requests using the following way

Expand Down Expand Up @@ -210,6 +224,16 @@ async def response_headers():
}
```


Additionally, you can access headers for per route.

```python
@app.get("/test-headers")
def sync_before_request(request: Request):
request.headers["test"] = "we are modifying the request headers in the middle of the request!"
print(rquest)
```

## Query Params

You can access query params from every HTTP method.
Expand Down Expand Up @@ -326,13 +350,15 @@ You can use both sync and async functions for middlewares!

```python
@app.before_request("/")
async def hello_before_request(request):
async def hello_before_request(request: Request):
request.headers["before"] = "sync_before_request"
print(request)


@app.after_request("/")
def hello_after_request(request):
print(request)
def hello_after_request(response: Response):
response.headers["after"] = "sync_after_request"
print(response)
```

## MultiCore Scaling
Expand Down Expand Up @@ -409,7 +435,7 @@ def sample_view():
return "Hello, world!"

def post(request):
body = bytearray(request["body"]).decode("utf-8")
body = request.body
return {"status_code": 200, "body": body}
```

Expand All @@ -425,7 +451,7 @@ def sync_decorator_view():
return "Hello, world!"

def post(request):
body = bytearray(request["body"]).decode("utf-8")
body = request.body
return {"status_code": 200, "body": body}


Expand All @@ -435,7 +461,7 @@ def async_decorator_view():
return "Hello, world!"

async def post(request):
body = bytearray(request["body"]).decode("utf-8")
body = request.body
return {"status_code": 200, "body": body}
```

Expand All @@ -449,7 +475,7 @@ def View():
return "Hello, world!"

async def post(request):
body = bytes(request["body"]).decode("utf-8")
body = request.body
return {
"status": 200,
"body": body,
Expand Down
4 changes: 2 additions & 2 deletions docs/graphql-integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ async def get():

@app.post("/")
async def post(request):
body = json.loads(bytearray(request["body"]).decode("utf-8"))
body = json.loads(request.body)
query = body["query"]
variables = body.get("variables", None)
context_value = {"request": request}
Expand Down Expand Up @@ -140,7 +140,7 @@ We are populating the html page with the GraphiQL IDE using `strawberry`. We are
```python
@app.post("/")
async def post(request):
body = json.loads(bytearray(request["body"]).decode("utf-8"))
body = json.loads(request.body)
query = body["query"]
variables = body.get("variables", None)
context_value = {"request": request}
Expand Down

0 comments on commit 0c00a06

Please sign in to comment.