README.rst: Unwind 'If ..., returns a 404' -> 'Returns a 404 if ...'
[nmhive.git] / README.rst
1 Nmhive is a webserver for nmbug_, allowing you to remotely query and
2 manage notmuch_ tags.  There is also a bookmarklet that provides a
3 convenient interface for managing tags while browsing Gmane_.
4
5 Dependencies
6 ============
7
8 * Flask_
9 * Flask-Cors_
10
11 The versions shouldn't matter too much, but I'm testing with Flask
12 0.10.1 and Flask-Cors 1.9.0.
13
14 Server setup
15 ============
16
17 Launch the server with something like::
18
19   $ nmhive.py -H 0.0.0.0 -p 5000
20    * Running on http://0.0.0.0:5000/
21   …
22
23 Use nmbug's usual ``NMBGIT`` and ``NMBPREFIX`` environment variables
24 to configure the nmbug repository used by nmhive.
25
26 You can kill the server whenever you like (e.g. via ``ctrl+c``)
27 without worrying about corrupting your local notmuch or nmbug
28 databases.
29
30 Then edit ``nmbug_server`` in ``nmbug.js`` to point at that interface.
31 Serve ``nmbug.js`` and ``index.html`` somewhere.  I serve them with
32 Nginx_, but you use whatever you like, including `Python's`__
33 `http.server`_ with something like::
34
35   $ python -m http.server 8000
36
37 __ Python_
38
39 Point your users to the served ``index.html`` so they can get the
40 bookmarklet and read the instructions for using it.
41
42 Endpoints
43 =========
44
45 The nmhive server provides the following endpoints for use by the
46 bookmarklet (or other tools):
47
48 ``GET /tags``
49   Returns the tags that are already stored in the nmbug database as a
50   JSON array.  Instead of requiring admins to configure a list of
51   available tags, we just assume all the tags are in use (and that no
52   non-standard tags are in use) under the ``NMBPREFIX``.
53
54 ``GET /mid/<message-id>``
55   Returns tags associated with a particular message as a JSON array.
56   Returns a 404 if the given Message-ID isn't in the notmuch database.
57
58 ``POST /mid/<message-id>``
59   Updates the tags associated with a particular message.  The posted
60   data should be a JSON array of tag-names with a prefix indicating
61   the desired change.  Use ``+`` to add a tag and ``-`` to remove a
62   tag.  For example::
63
64     $ curl -XPOST -H 'Content-Type: application/json' -d '["+obsolete", "-needs-review"]' http://localhost:5000/mid/e630b6763e9d0771718afee41ea15b29bb4a1de8.1409935538.git.wking@tremily.us
65     ["obsolete", "patch"]
66
67   Adding an already associated tag and removing an already
68   unassociated tag are both no-ops.  Returns the updated tags as a
69   JSON array.  Returns a 404 if the given Message-ID isn't in the
70   notmuch database.
71
72 ``GET /gmane/<group>/<article>``
73   Returns the article's Message-ID as ``text/plain``.  For example,
74   get the ``Message-ID`` of `this article`__ with::
75
76     $ curl -XGET http://localhost:5000/gmane/gmane.mail.notmuch.general/19007
77     e630b6763e9d0771718afee41ea15b29bb4a1de8.1409935538.git.wking@tremily.us
78
79 __ `Gmane Python nmbug v4`_
80
81
82 .. _nmbug: http://notmuchmail.org/nmbug/
83 .. _notmuch: http://notmuchmail.org/
84 .. _Gmane: http://gmane.org/
85 .. _Flask: http://flask.pocoo.org/
86 .. _Flask-Cors: https://pypi.python.org/pypi/Flask-Cors/
87 .. _Nginx: http://nginx.org/
88 .. _Python: https://www.python.org/
89 .. _http.server: https://docs.python.org/3/library/http.server.html
90 .. _Gmane Python nmbug v4: http://article.gmane.org/gmane.mail.notmuch.general/19007