Repository: aio-libs/aiohttp

Issue:
Implement router shortcuts
Add `router.add_get`, `router.add_post` and others.



Discussion:

Resolving patch:
diff --git a/aiohttp/web_urldispatcher.py b/aiohttp/web_urldispatcher.py
--- a/aiohttp/web_urldispatcher.py
+++ b/aiohttp/web_urldispatcher.py
@@ -738,3 +738,33 @@ def add_static(self, prefix, path, *, name=None, expect_handler=None,
                             response_factory=response_factory)
         self.register_route(route)
         return route
+
+    def add_get(self, *args, **kwargs):
+        """
+        Shortcut for add_route with method GET
+        """
+        return self.add_route('GET', *args, **kwargs)
+
+    def add_post(self, *args, **kwargs):
+        """
+        Shortcut for add_route with method POST
+        """
+        return self.add_route('POST', *args, **kwargs)
+
+    def add_put(self, *args, **kwargs):
+        """
+        Shortcut for add_route with method PUT
+        """
+        return self.add_route('PUT', *args, **kwargs)
+
+    def add_patch(self, *args, **kwargs):
+        """
+        Shortcut for add_route with method PATCH
+        """
+        return self.add_route('PATCH', *args, **kwargs)
+
+    def add_delete(self, *args, **kwargs):
+        """
+        Shortcut for add_route with method DELETE
+        """
+        return self.add_route('DELETE', *args, **kwargs)


Test patch:
diff --git a/tests/test_urldispatch.py b/tests/test_urldispatch.py
--- a/tests/test_urldispatch.py
+++ b/tests/test_urldispatch.py
@@ -89,6 +89,56 @@ def test_add_with_matchdict(self):
         self.assertIs(handler, info.handler)
         self.assertIsNone(info.route.name)
 
+    def test_add_route_with_add_get_shortcut(self):
+        handler = self.make_handler()
+        self.router.add_get('/handler/to/path', handler)
+        req = self.make_request('GET', '/handler/to/path')
+        info = self.loop.run_until_complete(self.router.resolve(req))
+        self.assertIsNotNone(info)
+        self.assertEqual(0, len(info))
+        self.assertIs(handler, info.handler)
+        self.assertIsNone(info.route.name)
+
+    def test_add_route_with_add_post_shortcut(self):
+        handler = self.make_handler()
+        self.router.add_post('/handler/to/path', handler)
+        req = self.make_request('POST', '/handler/to/path')
+        info = self.loop.run_until_complete(self.router.resolve(req))
+        self.assertIsNotNone(info)
+        self.assertEqual(0, len(info))
+        self.assertIs(handler, info.handler)
+        self.assertIsNone(info.route.name)
+
+    def test_add_route_with_add_put_shortcut(self):
+        handler = self.make_handler()
+        self.router.add_put('/handler/to/path', handler)
+        req = self.make_request('PUT', '/handler/to/path')
+        info = self.loop.run_until_complete(self.router.resolve(req))
+        self.assertIsNotNone(info)
+        self.assertEqual(0, len(info))
+        self.assertIs(handler, info.handler)
+        self.assertIsNone(info.route.name)
+
+    def test_add_route_with_add_patch_shortcut(self):
+        handler = self.make_handler()
+        self.router.add_patch('/handler/to/path', handler)
+        req = self.make_request('PATCH', '/handler/to/path')
+        info = self.loop.run_until_complete(self.router.resolve(req))
+        self.assertIsNotNone(info)
+        self.assertEqual(0, len(info))
+        self.assertIs(handler, info.handler)
+        self.assertIsNone(info.route.name)
+
+    def test_add_route_with_add_delete_shortcut(self):
+        handler = self.make_handler()
+        self.router.add_delete('/handler/to/path', handler)
+        req = self.make_request('DELETE', '/handler/to/path')
+        info = self.loop.run_until_complete(self.router.resolve(req))
+        self.assertIsNotNone(info)
+        self.assertEqual(0, len(info))
+        self.assertIs(handler, info.handler)
+        self.assertIsNone(info.route.name)
+
     def test_add_with_name(self):
         handler = self.make_handler()
         self.router.add_route('GET', '/handler/to/path', handler,