Skip to content

Commit

Permalink
Merge pull request #54 from starlite-api/optimization
Browse files Browse the repository at this point in the history
Optimization - iteration 1
  • Loading branch information
Goldziher authored Jan 23, 2022
2 parents f980c37 + a28bfb1 commit 107f9b4
Show file tree
Hide file tree
Showing 18 changed files with 546 additions and 202 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,10 @@
1. supports generics
2. added `to_model_instance` and `from_model_instance` methods
3. added `field_definitions` kwarg, allowing for creating custom fields


[0.7.0]
- optimization: rewrote route resolution
- optimization: updated query parameters parsing
- optimization: updated request-response cycle handling
- added `@asgi` route handler decorator
31 changes: 31 additions & 0 deletions docs/usage/2-route-handlers.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,37 @@ In all other regards websocket handlers function exactly like other route handle
OpenAPI currently does not support websockets. As a result not schema will be generated for websocket route
handlers, and you cannot configure any schema related parameters for these.


## ASGI Route Handlers

!!! info
This feature is available from v0.7.0 onwards

You can write your own ASGI apps using the `asgi` route handler decorator:

```python
from starlette.types import Scope, Receive, Send
from starlette.status import HTTP_200_OK, HTTP_400_BAD_REQUEST
from starlite import Response, asgi


@asgi(path="/my-asgi-app")
async def my_asgi_app(scope: Scope, receive: Receive, send: Send) -> None:
if scope["type"] == "http":
method = scope["method"]
if method.lower() == "get":
response = Response({"hello": "world"}, status_code=HTTP_200_OK)
await response(scope=scope, receive=receive, send=send)
return
response = Response(
{"detail": "unsupported request"}, status_code=HTTP_400_BAD_REQUEST
)
await response(scope=scope, receive=receive, send=send)
```

!!! note
ASGI apps are currently not handled in OpenAPI generation - although this might change in the future.

## Handler Function Kwargs

Route handler functions or methods access various data by declaring these as annotated function kwargs. The annotated
Expand Down
72 changes: 36 additions & 36 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "starlite"
version = "0.6.0"
version = "0.7.0"
description = "Light-weight and flexible ASGI API Framework"
authors = ["Na'aman Hirschfeld <[email protected]>"]
maintainers = ["Na'aman Hirschfeld <[email protected]>"]
Expand Down
28 changes: 16 additions & 12 deletions starlite/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@
StarLiteException,
)
from .handlers import (
ASGIRouteHandler,
BaseRouteHandler,
HTTPRouteHandler,
WebsocketRouteHandler,
asgi,
delete,
get,
patch,
Expand All @@ -49,18 +51,24 @@

__all__ = [
"AbstractAuthenticationMiddleware",
"asgi",
"ASGIRouteHandler",
"AuthenticationResult",
"BaseRoute",
"BaseRouteHandler",
"Body",
"CORSConfig",
"Controller",
"CORSConfig",
"create_test_client",
"create_test_request",
"delete",
"DTOFactory",
"File",
"get",
"HTTPException",
"HttpMethod",
"HTTPRoute",
"HTTPRouteHandler",
"HttpMethod",
"ImproperlyConfiguredException",
"InternalServerException",
"LoggingConfig",
Expand All @@ -74,33 +82,29 @@
"OpenAPIMediaType",
"Parameter",
"Partial",
"patch",
"PermissionDeniedException",
"PluginProtocol",
"post",
"Provide",
"put",
"Redirect",
"Request",
"RequestEncodingType",
"Response",
"ResponseHeader",
"route",
"Router",
"ScopeType",
"ServiceUnavailableException",
"StarLiteException",
"Starlite",
"StarLiteException",
"State",
"StaticFilesConfig",
"Stream",
"TestClient",
"WebSocket",
"websocket",
"WebSocketRoute",
"WebsocketRouteHandler",
"create_test_client",
"create_test_request",
"delete",
"get",
"patch",
"post",
"put",
"route",
"websocket",
]
Loading

0 comments on commit 107f9b4

Please sign in to comment.