Skip to content

Commit

Permalink
fix: replace body with description
Browse files Browse the repository at this point in the history
  • Loading branch information
sansyrox committed Sep 13, 2023
1 parent 256a0c4 commit c11c519
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 deletions.
14 changes: 7 additions & 7 deletions docs/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ Robyn accepts dictionaries to build a response for the route:
async def dictionary(request):
return {
"status_code": 200,
"body": "This is a regular response",
"description": "This is a regular response",
"type": "text",
"headers": {"Header": "header_value"},
}
Expand Down Expand Up @@ -210,7 +210,7 @@ You can also add request and response headers for every route.
async def request_headers():
return {
"status_code": 200,
"body": "",
"description": "",
"type": "text",
"headers": {"Header": "header_value"},
}
Expand Down Expand Up @@ -501,7 +501,7 @@ def sample_view():

def post(request):
body = request.body
return {"status_code": 200, "body": body}
return {"status_code": 200, "description": body}
```

The above view contains two closures for the `get` and the `post` request.
Expand All @@ -517,7 +517,7 @@ def sync_decorator_view():

def post(request):
body = request.body
return {"status_code": 200, "body": body}
return {"status_code": 200, "description": body}


@app.view("/async/view/decorator")
Expand All @@ -527,7 +527,7 @@ def async_decorator_view():

async def post(request):
body = request.body
return {"status_code": 200, "body": body}
return {"status_code": 200, "description": body}
```


Expand All @@ -543,7 +543,7 @@ def View():
body = request.body
return {
"status": 200,
"body": body,
"description": body,
"headers": {"Content-Type": "text/json"},
}
```
Expand Down Expand Up @@ -590,7 +590,7 @@ You can raise exceptions in your code and Robyn will handle them for you.
```python
@app.exception
def handle_exception(error):
return {"status_code": 500, "body": f"error msg: {error}"}
return {"status_code": 500, "description": f"error msg: {error}"}

```

Expand Down
34 changes: 17 additions & 17 deletions integration_tests/base_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ async def async_str_const_get():
def sync_dict_get():
return {
"status_code": 200,
"body": "sync dict get",
"description": "sync dict get",
"type": "text",
"headers": {"sync": "dict"},
}
Expand All @@ -228,7 +228,7 @@ def sync_dict_get():
async def async_dict_get():
return {
"status_code": 200,
"body": "async dict get",
"description": "async dict get",
"type": "text",
"headers": {"async": "dict"},
}
Expand All @@ -238,7 +238,7 @@ async def async_dict_get():
def sync_dict_const_get():
return {
"status_code": 200,
"body": "sync dict const get",
"description": "sync dict const get",
"type": "text",
"headers": {"sync_const": "dict"},
}
Expand All @@ -248,7 +248,7 @@ def sync_dict_const_get():
async def async_dict_const_get():
return {
"status_code": 200,
"body": "async dict const get",
"description": "async dict const get",
"type": "text",
"headers": {"async_const": "dict"},
}
Expand Down Expand Up @@ -456,19 +456,19 @@ async def async_query(request: Request):

@app.get("/404")
def return_404():
return {"status_code": 404, "body": "not found", "type": "text"}
return {"status_code": 404, "description": "not found", "type": "text"}


@app.get("/202")
def return_202():
return {"status_code": 202, "body": "hello", "type": "text"}
return {"status_code": 202, "description": "hello", "type": "text"}


@app.get("/307")
async def redirect():
return {
"status_code": 307,
"body": "",
"description": "",
"type": "text",
"headers": {"Location": "redirect_route"},
}
Expand Down Expand Up @@ -498,7 +498,7 @@ async def async_raise():
def sync_dict_post():
return {
"status_code": 200,
"body": "sync dict post",
"description": "sync dict post",
"type": "text",
"headers": {"sync": "dict"},
}
Expand All @@ -508,7 +508,7 @@ def sync_dict_post():
async def async_dict_post():
return {
"status_code": 200,
"body": "async dict post",
"description": "async dict post",
"type": "text",
"headers": {"async": "dict"},
}
Expand Down Expand Up @@ -536,7 +536,7 @@ async def async_body_post(request: Request):
def sync_dict_put():
return {
"status_code": 200,
"body": "sync dict put",
"description": "sync dict put",
"type": "text",
"headers": {"sync": "dict"},
}
Expand All @@ -546,7 +546,7 @@ def sync_dict_put():
async def async_dict_put():
return {
"status_code": 200,
"body": "async dict put",
"description": "async dict put",
"type": "text",
"headers": {"async": "dict"},
}
Expand Down Expand Up @@ -584,7 +584,7 @@ def sync_dict_delete():
async def async_dict_delete():
return {
"status_code": 200,
"body": "async dict delete",
"description": "async dict delete",
"type": "text",
"headers": {"async": "dict"},
}
Expand Down Expand Up @@ -612,7 +612,7 @@ async def async_body_delete(request: Request):
def sync_dict_patch():
return {
"status_code": 200,
"body": "sync dict patch",
"description": "sync dict patch",
"type": "text",
"headers": {"sync": "dict"},
}
Expand All @@ -622,7 +622,7 @@ def sync_dict_patch():
async def async_dict_patch():
return {
"status_code": 200,
"body": "async dict patch",
"description": "async dict patch",
"type": "text",
"headers": {"async": "dict"},
}
Expand Down Expand Up @@ -651,7 +651,7 @@ def get():

def post(request: Request):
body = request.body
return {"status_code": 200, "body": body}
return {"status_code": 200, "description": body}


@app.view("/async/view/decorator")
Expand All @@ -661,15 +661,15 @@ async def get():

async def post(request: Request):
body = request.body
return {"status_code": 200, "body": body}
return {"status_code": 200, "description": body}


# ==== Exception Handling ====


@app.exception
def handle_exception(error):
return {"status_code": 500, "body": f"error msg: {error}"}
return {"status_code": 500, "description": f"error msg: {error}"}


@app.get("/sync/exception/get")
Expand Down
2 changes: 1 addition & 1 deletion robyn/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def _format_response(self, res):
if isinstance(res, dict):
status_code = res.get("status_code", status_codes.HTTP_200_OK)
headers = res.get("headers", {"Content-Type": "text/plain"})
description = res.get("body", "")
description = res.get("description", "")

if type(status_code) != int:
status_code = int(status_code) # status_code can potentially be string
Expand Down

0 comments on commit c11c519

Please sign in to comment.