v0.0.4 Plugins / Extensions #76
cirospaciari
announced in
Announcements
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
What is changed in socketify:
res.send
andres.cork_send
Custom JSON Serializer
socketify by default uses built-in
json
module with has great performance on PyPy, but if you wanna use another module instead of the default you can just register usingapp.json_serializer(module)
Plugins / Extensions
You can add more functionality to request, response, and websocket objects, for this you can use
app.register(extension)
to register an extension.Be aware that using extensions can have a performance impact and using it with
request_response_factory_max_items
,websocket_factory_max_items
or the equivalent on CLI
--req-res-factory-maxitems
,--ws-factory-maxitems
will reduce this performance impact.Extensions must follow the signature
def extension(request, response, ws)
, request, response, and ws objects containmethod
decorator that binds a method to an instance,and also a
property(name: str, default_value: any = None)
that dynamic adds an property to the instance.Decorator Router
As the name suggests this router allows to use of decorators for routing and also comes up with a
prefix
option, and middleware support.res.send
andres.cork_send
res.send(message, content_type=b'text/plain, status=b'200 OK', headers=None, end_connection=False)
andres.cork_send(message, content_type=b'text/plain', status=b'200 OK', headers=None, end_connection=False)
combines
res.write_status()
,res.write_headers()
, andres.end()
in a way that is easier to use, if you want to send all in one call just using named parameters. Headers can receive any iterator of iterators/tuple likeiter(tuple(str, str))
where the first value is the header name and the following the value, usingres.cork_send
will make sure to send all thedata in a corked state.
Work in progress for v0.1.0:
This discussion was created from the release v0.0.4 Plugins / Extensions.
Beta Was this translation helpful? Give feedback.
All reactions