# ServeHandle for deployment created with a function with query\_params?

**URL:** <https://discuss.ray.io/t/servehandle-for-deployment-created-with-a-function-with-query-params/6291>\
**Category:** Ray Serve\
**Created:** [May 27, 2022, 12:03am UTC](https://discuss.ray.io/t/servehandle-for-deployment-created-with-a-function-with-query-params/6291 "2022-05-27T00:03:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nakamasato](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/nakamasato/32/2617_2.png) [@nakamasato](https://discuss.ray.io/u/nakamasato)\
**Post date:** [May 27, 2022, 12:03am UTC](https://discuss.ray.io/t/servehandle-for-deployment-created-with-a-function-with-query-params/6291/1 "2022-05-27T00:03:44Z")

</div>

**How severe does this issue affect your experience of using Ray?**

- Low: It annoys or frustrates me for a moment.

When I tried combining what’s written in the documentation, I encountered into an issue related to ServeHandle for a deployment created with a function.

I created the following Serve Deployment, which is simplified one of the router example in the [doc](https://docs.ray.io/en/latest/serve/end_to_end_tutorial.html)

```python
import ray
from ray import serve

ray.init(address="auto", namespace="serve")
serve.start(detached=True)

@serve.deployment
def router(request):
    txt = request.query_params["txt"]
    return txt

router.deploy()

```

I could confirm with HTTP request with txt as a parameter.

And I also tried to access to this deployment via Python, but I couldn’t find a way to do that. I read a [best practice](https://docs.ray.io/en/latest/serve/http-servehandle.html#servehandle-calling-deployments-from-python) to separate a method to call using ServeHandle like:

```python
@serve.deployment(route_prefix="/api")
class Deployment:
    def say_hello(self, name: str):
        return f"Hello {name}!"

    def __call__ (self, request):
        return self.say_hello(request.query_params["name"])

```

It worked perfectly, but I’m wondering if there’s a way to send a request via ServeHandle for deployment created with a function.

Thank you in advance!

---

<div class="post-metadata">

**Author:** ![eoakes](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/eoakes/32/7825_2.png) [@eoakes](https://discuss.ray.io/u/eoakes)\
**Post date:** [May 27, 2022, 12:04am UTC](https://discuss.ray.io/t/servehandle-for-deployment-created-with-a-function-with-query-params/6291/2 "2022-05-27T00:04:48Z")

</div>

@nakamasato I would recommend that you use a separate method in a class for this use case (as you figured out!).

---

<div class="post-metadata">

**Author:** ![nakamasato](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/nakamasato/32/2617_2.png) [@nakamasato](https://discuss.ray.io/u/nakamasato)\
**Post date:** [May 27, 2022, 12:09am UTC](https://discuss.ray.io/t/servehandle-for-deployment-created-with-a-function-with-query-params/6291/3 "2022-05-27T00:09:18Z")

</div>

@eoakes Thank you for your super quick reply! I’ll use the best practice!  
It seems that supporting a function with the @serve.deployment annotation is for a simple use case, and if there’s more requirements like to support multiple access ways with parameters, it’s recommended to use a class. Is my understanding correct?

---

<div class="post-metadata">

**Author:** ![eoakes](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/eoakes/32/7825_2.png) [@eoakes](https://discuss.ray.io/u/eoakes)\
**Post date:** [May 27, 2022, 12:10am UTC](https://discuss.ray.io/t/servehandle-for-deployment-created-with-a-function-with-query-params/6291/4 "2022-05-27T00:10:40Z")

</div>

Yep, that’s exactly right. The function use case is mostly there for simple examples 🙂

---

<div class="post-metadata">

**Author:** ![nakamasato](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/nakamasato/32/2617_2.png) [@nakamasato](https://discuss.ray.io/u/nakamasato)\
**Post date:** [May 27, 2022, 12:12am UTC](https://discuss.ray.io/t/servehandle-for-deployment-created-with-a-function-with-query-params/6291/5 "2022-05-27T00:12:14Z")

</div>

Thank you for your confirmation!
