diff --git a/CHANGELOG b/CHANGELOG index 72c2156..9787e34 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -4,6 +4,8 @@ Changelog 2.4 (dev) ---------------- +* API accepts the format or lexer via GET too. You can call an API url like + ``example.com/api/?format=json`` and have the body in POST only. * Added an option to keep snippets forever 2.3 (2014-01-07) diff --git a/docs/api.rst b/docs/api.rst index fcbdb63..a33a20f 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -20,13 +20,13 @@ Required. The UTF-8 encoded string you want to paste. ``lexer`` (optional) ~~~~~~~~~~~~~~~~~~~~ -Optional. The lexer string key used for highlighting. See `lexer list`_ for -a full list of choices. Default: ``python``. +Optional. Can also be set via GET. The lexer string key used for highlighting. +See `lexer list`_ for a full list of choices. Default: ``python``. ``format`` (optional) ~~~~~~~~~~~~~~~~~~~~~ -Optional. The format of the API response. Choices are: +Optional. Can also be set via GET. The format of the API response. Choices are: * ``default`` — Returns a full qualified URL wrapped in quotes. Example:: @@ -80,5 +80,6 @@ A sample Python 2 script to publish snippets:: You can simply use curl to publish a whole file:: - $ alias dpaste="curl -F 'content=<-' https://dpaste.de/api/" + $ alias dpaste="curl -F 'content=<-' https://dpaste.de/api/?format=url" $ cat foo.txt | dpaste + https://dpaste.de/ke2pB diff --git a/dpaste/views.py b/dpaste/views.py index 1a757d0..6c86d7a 100644 --- a/dpaste/views.py +++ b/dpaste/views.py @@ -269,8 +269,8 @@ FORMAT_MAPPING = { @csrf_exempt def snippet_api(request): content = request.POST.get('content', '').strip() - lexer = request.POST.get('lexer', LEXER_DEFAULT).strip() - format = request.POST.get('format', 'default').strip() + lexer = request.REQUEST.get('lexer', LEXER_DEFAULT).strip() + format = request.REQUEST.get('format', 'default').strip() if not content: return HttpResponseBadRequest('No content given')