Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: split request params #952

Open
wants to merge 59 commits into
base: main
Choose a base branch
from

Conversation

VishnuSanal
Copy link
Contributor

@VishnuSanal VishnuSanal commented Aug 26, 2024

Description

This PR fixes #850

Summary

This PR does split request params

PR Checklist

Please ensure that:

  • The PR contains a descriptive title
  • The PR contains a descriptive summary of the changes
  • You build and test your changes before submitting a PR.
  • You have added relevant documentation
  • You have added relevant tests. We prefer integration tests wherever possible

Pre-Commit Instructions:

Copy link

vercel bot commented Aug 26, 2024

@VishnuSanal is attempting to deploy a commit to the sparckles Team on Vercel.

A member of the Team first needs to authorize it.

@VishnuSanal VishnuSanal changed the title feat: [WIP] split request params feat: split request params Aug 28, 2024
@VishnuSanal
Copy link
Contributor Author

@sansyrox, the tests pass here. can you PTAL at the interface + an initial review, if you will. :)

@VishnuSanal VishnuSanal marked this pull request as ready for review August 28, 2024 10:11
Copy link

codspeed-hq bot commented Aug 28, 2024

CodSpeed Performance Report

Merging #952 will not alter performance

Comparing VishnuSanal:split-request-params (acf76ca) with main (028f161)

Summary

✅ 116 untouched benchmarks

🆕 29 new benchmarks

Benchmarks breakdown

Benchmark main VishnuSanal:split-request-params Change
🆕 test_openapi_query_params N/A 6.4 ms N/A
🆕 test_split_request_params_get_body[split_request_typed-async] N/A 4.9 ms N/A
🆕 test_split_request_params_get_body[split_request_typed-sync] N/A 4.9 ms N/A
🆕 test_split_request_params_get_body[split_request_untyped-async] N/A 4.9 ms N/A
🆕 test_split_request_params_get_body[split_request_untyped-sync] N/A 4.9 ms N/A
🆕 test_split_request_params_get_combined[split_request_typed-async] N/A 5.1 ms N/A
🆕 test_split_request_params_get_combined[split_request_typed-sync] N/A 5.1 ms N/A
🆕 test_split_request_params_get_combined[split_request_untyped-async] N/A 5.1 ms N/A
🆕 test_split_request_params_get_combined[split_request_untyped-sync] N/A 5.1 ms N/A
🆕 test_split_request_params_get_combined_failure[async] N/A 5.1 ms N/A
🆕 test_split_request_params_get_combined_failure[sync] N/A 5.1 ms N/A
🆕 test_split_request_params_get_headers[split_request_typed-async] N/A 4.8 ms N/A
🆕 test_split_request_params_get_headers[split_request_typed-sync] N/A 4.9 ms N/A
🆕 test_split_request_params_get_headers[split_request_untyped-async] N/A 4.9 ms N/A
🆕 test_split_request_params_get_headers[split_request_untyped-sync] N/A 4.9 ms N/A
🆕 test_split_request_params_get_method[split_request_typed-async] N/A 4.9 ms N/A
🆕 test_split_request_params_get_method[split_request_typed-sync] N/A 4.8 ms N/A
🆕 test_split_request_params_get_method[split_request_untyped-async] N/A 4.9 ms N/A
🆕 test_split_request_params_get_method[split_request_untyped-sync] N/A 4.9 ms N/A
🆕 test_split_request_params_get_path_params[split_request_typed-async] N/A 4.9 ms N/A
... ... ... ... ...

ℹ️ Only the first 20 benchmarks are displayed. Go to the app to view all benchmarks.

@sansyrox
Copy link
Member

Hey @VishnuSanal 👋

I really like the current implementation. Great job ✨ But I have a few follow ups. I will share them in a few hours

robyn/router.py Outdated Show resolved Hide resolved
@VishnuSanal
Copy link
Contributor Author

VishnuSanal commented Aug 31, 2024

  • create custom type aliases & check them in the funciton signature

@VishnuSanal
Copy link
Contributor Author

image

@sansyrox this is the swagger page for the following robyn app.

from typing import Optional

from robyn import Robyn
from robyn.types import Body, QueryParams, JSONResponse

app = Robyn(__file__)


class CreateItemBody(Body):
    name: Optional[str]
    description: str
    price: float
    tax: float


class CreateItemQueryParams(QueryParams):
    _id: int
    desc: Optional[str]


class CreateItemResponse(JSONResponse):
    body: CreateItemBody
    qp: CreateItemQueryParams


@app.post("/upload/file")
def create_item(body_item: CreateItemBody, query: CreateItemQueryParams) -> int:
    print(body_item, query)
    return 200


app.start()

robyn/robyn.pyi Outdated Show resolved Hide resolved
robyn/robyn.pyi Outdated Show resolved Hide resolved
robyn/types.py Outdated Show resolved Hide resolved
src/types/identity.rs Outdated Show resolved Hide resolved
src/types/mod.rs Outdated Show resolved Hide resolved
@VishnuSanal
Copy link
Contributor Author

@sansyrox PTAL :)

@@ -89,7 +89,7 @@ class Url:
class Identity:
claims: dict[str, str]

class QueryParams:
class RustQueryParams:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be just QueryParams. No?

@@ -8,7 +8,7 @@ def test_request_object():
path="/user",
)
request = Request(
query_params=QueryParams(),
query_params=RustQueryParams(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this should be QueryParams. No part of the client facing code should require us to initialise RustQueryParams

robyn/types.py Outdated
Comment on lines 29 to 48
"""
A type alias for openapi response bodies
"""

pass


class Body:
"""
A type alias for openapi request bodies
"""

pass


class QueryParams:
"""
A type alias for query params type annotations
"""

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the docstrings still need work

Comment on lines +44 to +48
class QueryParams:
"""
A type alias for query params type annotations
"""

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also you should implement the method definitions here. Associated with rust query params.

src/types/mod.rs Outdated Show resolved Hide resolved
src/types/identity.rs Outdated Show resolved Hide resolved
@sansyrox
Copy link
Member

sansyrox commented Oct 6, 2024

Hey @VishnuSanal , some more work is needed here. Also , could you have a look at the conflicts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants