From 78fff98712d95c7ff5275f2d39113ceee02db2e2 Mon Sep 17 00:00:00 2001
From: Vladimir Berkutov <dair.targ@gmail.com>
Date: Sat, 16 Jun 2012 20:08:31 +0400
Subject: [PATCH] Issue #54 Method suggestion proposal

---
 httpie/__main__.py | 7 +++++++
 httpie/cli.py      | 2 ++
 tests/tests.py     | 6 ++++++
 3 files changed, 15 insertions(+)

diff --git a/httpie/__main__.py b/httpie/__main__.py
index 8f19f6d4..2e32f7c4 100644
--- a/httpie/__main__.py
+++ b/httpie/__main__.py
@@ -1,4 +1,5 @@
 #!/usr/bin/env python
+import re
 import sys
 import json
 
@@ -40,6 +41,12 @@ def _get_response(parser, args, stdin, stdin_isatty):
         # Form
         args.headers['Content-Type'] = TYPE_FORM
 
+    if args.method is None and not args.items:
+        args.method = 'GET'
+    elif not re.match('^[a-zA-Z]+$', args.method):
+        args.items.insert(0, args.url)
+        args.method, args.url = 'POST', args.method
+
     # Fire the request.
     try:
         credentials = None
diff --git a/httpie/cli.py b/httpie/cli.py
index 62ca44c2..36e82474 100644
--- a/httpie/cli.py
+++ b/httpie/cli.py
@@ -171,6 +171,8 @@ parser.add_argument(
 
 parser.add_argument(
     'method', metavar='METHOD',
+    nargs='?',
+    default=None,
     help=_('''
         The HTTP method to be used for the request
         (GET, POST, PUT, DELETE, PATCH, ...).
diff --git a/tests/tests.py b/tests/tests.py
index 44b7ddf6..03e0a712 100644
--- a/tests/tests.py
+++ b/tests/tests.py
@@ -144,6 +144,12 @@ class TestHTTPie(BaseTest):
         self.assertIn('"User-Agent": "HTTPie', response)
         self.assertIn('"Foo": "bar"', response)
 
+    def test_get_suggestion(self):
+        http('http://httpbin.org/get')
+
+    def test_post_suggestion(self):
+        http('http://httpbin.org/post', 'hello=world')
+
 
 class TestPrettyFlag(BaseTest):
     """Test the --pretty / --ugly flag handling."""