Skip to content

Commit 60da61b

Browse files
committed
First attempt at some API documentation.
- Legacy-Id: 12830
1 parent 553338f commit 60da61b

1 file changed

Lines changed: 96 additions & 0 deletions

File tree

ietf/static/ietf/doc/api.rst

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
=====================
2+
Datatracker API Notes
3+
=====================
4+
5+
6+
Framework
7+
=========
8+
9+
The api uses tastypie (https://django-tastypie.readthedocs.org/)
10+
to generate an API which mirrors the Django ORM (Object Relational Mapping)
11+
for the database. Each Django model class maps down to the SQL database
12+
tables and up to the API. The Django models classes are defined in the
13+
models.py files of the datatracker:
14+
15+
http://svn.tools.ietf.org/svn/tools/ietfdb/trunk/ietf/doc/models.py
16+
http://svn.tools.ietf.org/svn/tools/ietfdb/trunk/ietf/group/models.py
17+
http://svn.tools.ietf.org/svn/tools/ietfdb/trunk/ietf/iesg/models.py
18+
...
19+
20+
The API top endpoint is at https://datatracker.ietf.org/api/v1/. The top
21+
endpoint lists inferior endpoints, and thus permits some autodiscovery,
22+
but there's really no substitute for looking at the actual ORM model classes.
23+
Comparing a class in models.py with the equivalent endpoint may give
24+
some clue (note that in the case of Group, it's a subclass of GroupInfo):
25+
26+
https://datatracker.ietf.org/api/v1/group/group/
27+
https://trac.tools.ietf.org/tools/ietfdb/browser/trunk/ietf/group/models.py#L14
28+
29+
Data is currently provided in JSON and XML format. Adding new formats is
30+
fairly easy, if it should be found desriable.
31+
32+
33+
Documents
34+
=========
35+
36+
Documents are listed at https://datatracker.ietf.org/api/v1/doc/document/ .
37+
38+
In general, individual database objects are represented in the api with a path
39+
composed of the model collection, the object name, and the object key. Most
40+
objects have simple numerical keys, but documents have the document name as
41+
key. Take draft-ietf-eppext-keyrelay. Documents have a model 'Document' which
42+
is described in the 'doc' models.py file. Assembling the path components
43+
'doc', 'document' (lowercase!) and 'draft-ietf-eppext-keyrelay', we get the
44+
URL:
45+
46+
https://datatracker.ietf.org/api/v1/doc/document/draft-ietf-eppext-keyrelay/
47+
48+
If you instead do a search for this document, you will get a machine-readable
49+
search result, which is composed of some meta-information about the search,
50+
and a list with one element:
51+
52+
https://datatracker.ietf.org/api/v1/doc/document/?name=draft-ietf-eppext-keyrelay
53+
54+
To search for documents based on state, you need to know that documents have
55+
multiple orthogonal states:
56+
57+
- If a document has an rfc-editor state, you can select for it by asking for
58+
documents which match 'states__type__slug__in=draft-rfceditor'::
59+
60+
$ curl 'https://datatracker.ietf.org/api/v1/doc/document/?limit=0&name__contains=-v6ops-&states__type__slug__in=draft-rfceditor' | python -m json.tool
61+
62+
- If a document has an iesg state, you can select for it by asking for
63+
documents which match ``'states__type__slug__in=draft-iesg'``
64+
65+
- If a document has a WG state, you can select for it by asking for
66+
documents which match ``'states__type__slug__in=draft-stream-ietf'``
67+
68+
- States which match ``'states__type__slug__in=draft'`` describe the basic
69+
Active/Expired/Dead whatever state of the draft.
70+
71+
You could use this in at least two alternative ways:
72+
73+
You could either fetch and remember the different state groups of interest to you
74+
with queries like::
75+
76+
$ curl 'https://datatracker.ietf.org/api/v1/doc/state/?format=json&limit=0&type__slug__in=draft-rfceditor'
77+
78+
$ curl 'https://datatracker.ietf.org/api/v1/doc/state/?format=json&limit=0&type__slug__in=draft-iesg'
79+
80+
$ curl 'https://datatracker.ietf.org/api/v1/doc/state/?format=json&limit=0&type__slug__in=draft-stream-ietf'
81+
82+
and then match the listed "resource_uri" of the results to the states listed for each
83+
document when you ask for:
84+
85+
$ curl 'https://datatracker.ietf.org/api/v1/doc/document/?limit=0&name__contains=-v6ops-'
86+
87+
Or alternatively you could do a series of queries asking for matches to the RFC Editor
88+
state first, then the IESG state, then the Stream state, and exclude earlier hits:
89+
90+
$ curl 'https://datatracker.ietf.org/api/v1/doc/document/?limit=0\\
91+
&name__contains=-v6ops-&states__type__slug__in=draft-rfceditor' ...
92+
93+
$ curl 'https://datatracker.ietf.org/api/v1/doc/document/?limit=0\\
94+
&name__contains=-v6ops-&states__type__slug__in=draft-iesg' ...
95+
96+
etc.

0 commit comments

Comments
 (0)