diff --git a/integration_tests/base_routes.py b/integration_tests/base_routes.py index 62d0a5baa..e21a15b74 100644 --- a/integration_tests/base_routes.py +++ b/integration_tests/base_routes.py @@ -5,7 +5,6 @@ from typing import Optional from robyn import ( - HttpMethod, Request, Response, Robyn, @@ -731,12 +730,12 @@ async def async_without_decorator(): return "Success!" -app.add_route(HttpMethod.GET, "/sync/get/no_dec", sync_without_decorator) -app.add_route(HttpMethod.PUT, "/sync/put/no_dec", sync_without_decorator) -app.add_route(HttpMethod.POST, "/sync/post/no_dec", sync_without_decorator) -app.add_route(HttpMethod.GET, "/async/get/no_dec", async_without_decorator) -app.add_route(HttpMethod.PUT, "/async/put/no_dec", async_without_decorator) -app.add_route(HttpMethod.POST, "/async/post/no_dec", async_without_decorator) +app.add_route("GET", "/sync/get/no_dec", sync_without_decorator) +app.add_route("PUT", "/sync/put/no_dec", sync_without_decorator) +app.add_route("POST", "/sync/post/no_dec", sync_without_decorator) +app.add_route("GET", "/async/get/no_dec", async_without_decorator) +app.add_route("PUT", "/async/put/no_dec", async_without_decorator) +app.add_route("POST", "/async/post/no_dec", async_without_decorator) # ===== Main ===== diff --git a/robyn/__init__.py b/robyn/__init__.py index c1e31fefd..ca54a5e2f 100644 --- a/robyn/__init__.py +++ b/robyn/__init__.py @@ -2,7 +2,7 @@ import logging import multiprocess as mp import os -from typing import Callable, List, Optional, Tuple +from typing import Callable, List, Optional, Tuple, Union from nestd import get_all_nested @@ -67,7 +67,7 @@ def __init__(self, file_object: str, config: Config = Config()) -> None: def add_route( self, - route_type: HttpMethod, + route_type: Union[HttpMethod, str], endpoint: str, handler: Callable, is_const: bool = False, @@ -87,6 +87,17 @@ def add_route( """ if auth_required: self.middleware_router.add_auth_middleware(endpoint)(handler) + if isinstance(route_type, str): + http_methods = { + "GET": HttpMethod.GET, + "POST": HttpMethod.POST, + "PUT": HttpMethod.PUT, + "DELETE": HttpMethod.DELETE, + "PATCH": HttpMethod.PATCH, + "HEAD": HttpMethod.HEAD, + "OPTIONS": HttpMethod.OPTIONS, + } + route_type = http_methods[route_type] return self.router.add_route( route_type, endpoint, handler, is_const, self.exception_handler