API call accepts the lexer or format parameters now via GET too.

With this you can set the format by the url: /api/?format=json
This commit is contained in:
Martin Mahner 2014-01-11 16:09:11 +01:00
parent d3e497df4c
commit dbfbcf54b6
3 changed files with 9 additions and 6 deletions

View file

@ -4,6 +4,8 @@ Changelog
2.4 (dev) 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 * Added an option to keep snippets forever
2.3 (2014-01-07) 2.3 (2014-01-07)

View file

@ -20,13 +20,13 @@ Required. The UTF-8 encoded string you want to paste.
``lexer`` (optional) ``lexer`` (optional)
~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~
Optional. The lexer string key used for highlighting. See `lexer list`_ for Optional. Can also be set via GET. The lexer string key used for highlighting.
a full list of choices. Default: ``python``. See `lexer list`_ for a full list of choices. Default: ``python``.
``format`` (optional) ``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:: * ``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:: 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 $ cat foo.txt | dpaste
https://dpaste.de/ke2pB

View file

@ -269,8 +269,8 @@ FORMAT_MAPPING = {
@csrf_exempt @csrf_exempt
def snippet_api(request): def snippet_api(request):
content = request.POST.get('content', '').strip() content = request.POST.get('content', '').strip()
lexer = request.POST.get('lexer', LEXER_DEFAULT).strip() lexer = request.REQUEST.get('lexer', LEXER_DEFAULT).strip()
format = request.POST.get('format', 'default').strip() format = request.REQUEST.get('format', 'default').strip()
if not content: if not content:
return HttpResponseBadRequest('No content given') return HttpResponseBadRequest('No content given')