dpaste/docs/api.rst

135 lines
3.9 KiB
ReStructuredText
Raw Normal View History

2019-12-09 05:39:43 +11:00
===
API
===
API endpoint
2018-06-24 05:12:46 +10:00
============
2014-01-07 23:36:02 +11:00
dpaste provides a simple API endpoint to create new snippets. All you need to
2018-06-24 05:12:46 +10:00
do is a simple ``POST`` request to the API endpoint, usually ``/api/``:
2014-01-07 23:36:02 +11:00
2018-06-24 05:12:46 +10:00
.. http:post:: /api/
2014-01-07 23:36:02 +11:00
2018-06-24 05:12:46 +10:00
Create a new Snippet on this dpaste installation. It returns the full
URL that snippet was created.
2014-01-07 23:36:02 +11:00
2018-06-24 05:12:46 +10:00
**Example request**:
2014-01-07 23:36:02 +11:00
2018-06-24 05:12:46 +10:00
.. code-block:: bash
2014-01-07 23:36:02 +11:00
2018-06-24 05:12:46 +10:00
$ curl -X POST -F "format=url" -F "content=ABC" https:/dpaste.de/api/
2014-01-07 23:36:02 +11:00
2018-06-24 05:12:46 +10:00
Host: dpaste.de
User-Agent: curl/7.54.0
Accept: */*
2014-01-07 23:36:02 +11:00
2018-06-24 05:12:46 +10:00
**Example response**:
2014-01-07 23:36:02 +11:00
2018-06-24 05:12:46 +10:00
.. sourcecode:: json
2014-01-07 23:36:02 +11:00
2018-06-24 05:12:46 +10:00
{
"lexer": "python",
"url": "https://dpaste.de/EBKU",
"content": "ABC"
}
2014-01-07 23:36:02 +11:00
2018-06-24 05:12:46 +10:00
:form content: (required) The UTF-8 encoded string you want to paste.
2014-01-07 23:36:02 +11:00
2018-06-24 05:12:46 +10:00
:form lexer: (optional) The lexer string key used for highlighting. See
the ``CODE_FORMATTER`` property in :ref:`settings` for a full list
of choices. Default: ``_code``.
2014-01-07 23:36:02 +11:00
2018-06-24 05:12:46 +10:00
:form format: (optional) The format of the API response. Choices are:
2014-01-07 23:36:02 +11:00
2018-06-24 05:12:46 +10:00
* ``default`` — Returns a full qualified URL wrapped in quotes.
Example: ``"https://dpaste.de/xsWd"``
2014-01-07 23:36:02 +11:00
2018-06-24 05:12:46 +10:00
* ``url`` — Returns the full qualified URL to the snippet, without surrounding
quotes, but with a line break. Example: ``https://dpaste.de/xsWd\n``
2018-06-24 05:12:46 +10:00
* ``json`` — Returns a JSON object containing the URL, lexer and content of the
the snippet. Example:
2018-06-24 05:12:46 +10:00
.. code-block:: json
2018-06-24 05:12:46 +10:00
{
"url": "https://dpaste.de/xsWd",
"lexer": "python",
"content": "The text body of the snippet."
}
2018-06-24 05:12:46 +10:00
:form expires: (optional) A keyword to indicate the lifetime of a snippet in
seconds. The values are
predefined by the server. Calling this with an invalid value returns a HTTP 400
BadRequest together with a list of valid values. Default: ``2592000``. In the
default configuration valid values are:
2018-06-24 05:12:46 +10:00
* onetime
* never
* 3600
* 604800
* 2592000
2018-06-24 05:12:46 +10:00
:form filename: (optional) A filename which we use to determine a lexer, if
``lexer`` is not set. In case we can't determine a file, the lexer will
fallback to ``plain`` code (no highlighting). A given ``lexer`` will overwrite
any filename! Example:
2018-06-24 05:12:46 +10:00
.. code-block:: json
2018-06-24 05:12:46 +10:00
{
"url": "https://dpaste.de/xsWd",
"lexer": "",
"filename": "python",
"content": "The text body of the snippet."
}
2018-06-24 05:12:46 +10:00
This will create a ``python`` highlighted snippet. However in this example:
2018-06-24 05:12:46 +10:00
.. code-block:: json
2014-01-07 23:36:02 +11:00
2018-06-24 05:12:46 +10:00
{
"url": "https://dpaste.de/xsWd",
"lexer": "php",
"filename": "python",
"content": "The text body of the snippet."
}
2014-01-07 23:36:02 +11:00
2018-06-24 05:12:46 +10:00
Since the lexer is set too, we will create a ``php`` highlighted snippet.
2014-01-12 02:03:50 +11:00
2018-06-24 05:12:46 +10:00
:statuscode 200: No Error.
:statuscode 400: One of the above form options was invalid,
the response will contain a meaningful error message.
2014-01-12 02:03:50 +11:00
2019-12-09 05:39:43 +11:00
.. hint:: If you have a standalone installation and your API returns
``https://dpaste-base-url.example.org`` as the domain, you need to adjust
the setting ``get_base_url`` property. See :ref:`settings`.
2014-01-12 02:03:50 +11:00
2019-12-09 05:39:43 +11:00
Third party API integration
===========================
2014-01-12 02:03:50 +11:00
2018-06-24 05:12:46 +10:00
subdpaste
a Sublime Editor plugin: https://github.com/bartTC/SubDpaste
Marmalade
an Emacs plugin: http://marmalade-repo.org/packages/dpaste_de
atom-dpaste
for the Atom editor: https://atom.io/packages/atom-dpaste
dpaste-magic
2019-01-02 23:49:52 +11:00
an iPython extension: https://pypi.org/project/dpaste-magic/
2014-01-12 02:03:50 +11:00
2018-06-24 05:12:46 +10:00
You can also paste your file content to the API via curl, directly from the
command line:
2014-01-12 02:03:50 +11:00
2018-06-24 05:12:46 +10:00
.. code-block:: bash
2014-01-12 02:03:50 +11:00
2020-05-18 20:20:23 +10:00
$ alias dpaste="curl -F 'format=url' -F 'content=<-' https://dpaste.org/api/"
2014-01-12 02:03:50 +11:00
$ cat foo.txt | dpaste
https://dpaste.org/ke2pB
2018-06-24 05:12:46 +10:00
.. note:: If you wrote or know a third party dpaste plugin or extension,
please open an *Issue* on Github_ and it's added here.
.. _Github: https://github.com/bartTC/dpaste