mirror of
https://github.com/wassname/ray.git
synced 2026-08-11 11:24:51 +08:00
[serve] Add example code for custom status code response (#13868)
This commit is contained in:
@@ -73,6 +73,20 @@ To call a method via Python, use :mod:`handle.options <ray.serve.handle.RayServe
|
||||
The call is the same as a regular query except a different method is called
|
||||
within the replica. It is compatible with batching as well.
|
||||
|
||||
How do I use custom status codes in my response?
|
||||
---------------------------------------------------------
|
||||
|
||||
You can return a `Starlette Response object <https://www.starlette.io/responses/>`_ from your backend code:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from starlette.responses import Response
|
||||
|
||||
def f(starlette_request):
|
||||
return Response('Hello, world!', status_code=123, media_type='text/plain')
|
||||
|
||||
client.create_backend("hello", f)
|
||||
|
||||
How do I enable CORS and other HTTP features?
|
||||
---------------------------------------------
|
||||
|
||||
|
||||
Reference in New Issue
Block a user