Skip to content

Commit 57da1f7

Browse files
authored
Re-work around design document for APIv3 (#5845)
Re-work around design document for APIv3
2 parents 83d8158 + 250ee1f commit 57da1f7

File tree

1 file changed

+106
-142
lines changed

1 file changed

+106
-142
lines changed

docs/development/design/apiv3.rst

Lines changed: 106 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -1,204 +1,168 @@
1-
Design of APIv3
2-
===============
1+
=======================
2+
APIv3 Design Document
3+
=======================
4+
5+
This document describes the design,
6+
some decisions already made and built (current Version 1 of APIv3)
7+
and an implementation plan for next Versions of APIv3.
38

49
APIv3 will be designed to be easy to use and useful to perform read and write operations as the main two goals.
510

611
It will be based on Resources as APIv2 but considering the ``Project`` resource as the main one,
712
from where most of the endpoint will be based on it.
813

14+
.. contents::
15+
:local:
16+
:backlinks: none
17+
:depth: 1
918

10-
Problems with APIv2
11-
-------------------
12-
13-
14-
* No authentication
15-
* It's read-only
16-
* Not designed for slugs
17-
* Useful APIs not exposed (only for internal usage currently)
18-
* Error reporting is a mess
19-
* Relationships between API resources is not obvious
20-
* Footer API endpoint returns HTML
21-
22-
23-
Proposed improves
24-
+++++++++++++++++
25-
26-
27-
Use authentication
28-
~~~~~~~~~~~~~~~~~~
29-
30-
* Pros:
31-
32-
* queries can be personalized depending on the user
33-
* allows us to perform write actions
34-
35-
* Cons:
36-
37-
* harder to implement
38-
* requires a lot of time for good testing and QA
39-
40-
41-
Questions:
42-
43-
#. Do we want make auth a requirement?
44-
#. Should we expose some endpoints as Read Only if not authenticated?
45-
#. How we do communicate users about deprecation if they are Anonymous? Is it enough to add a note in the docs saying that "Auth is preferred for communication"?
46-
#. How are we going to expose the ``Token`` required for Auth when building if auth is mandatory?
47-
48-
49-
Read and Write
50-
~~~~~~~~~~~~~~
5119

52-
* Pros:
20+
Goals
21+
-----
5322

54-
* most of the actions can be performed by a script instead of by
55-
accessing readthedocs.org with a browser
23+
* Easy to use for our users (access most of resources by ``slug``)
24+
* Useful to perform read and write operations
25+
* Authentication/Authorization
5626

57-
* Cons:
27+
* Authentication based on scoped-tokens
28+
* Handle Authorization nicely using an abstraction layer
5829

59-
* we have to deal with authorization
60-
* open the door to possibilities of security holes
30+
* Cover most useful cases:
6131

32+
* Integration on CI (check build status, trigger new build, etc)
33+
* Usage from public Sphinx/MkDocs extensions
34+
* Allow creation of flyout menu client-side
35+
* Simplify migration from other services (import projects, create multiple redirects, etc)
6236

63-
Questions:
6437

65-
#. Do we want to allow the user to perform **all the write actions**
66-
that are possible to do from the dashboard via the API?
67-
68-
69-
Design it for slugs
70-
~~~~~~~~~~~~~~~~~~~
71-
72-
* Pros:
73-
74-
* knowing the slug of your project (which is presented to the user)
75-
you can perform all the actions or retrieve all the data
76-
77-
* Cons:
78-
79-
* it will be a mixture between most of the endpoint using ``slug``
80-
and to retrieve details of a Build it will be an ``id``
81-
82-
83-
Expose internal endpoints
84-
~~~~~~~~~~~~~~~~~~~~~~~~~
85-
86-
There are some endpoints that we are using internally like
87-
``/api/v2/search/``, ``/api/v2/footer/`` and
88-
``/api/v2/sustainability/``.
89-
90-
91-
* Pros:
92-
93-
* allow to build custom footer
94-
* allow to build custom search autocomplete widget
95-
96-
* Cons:
38+
Non-Goals
39+
---------
9740

98-
* n/a
41+
* Filter by arbitrary and non-useful fields
9942

100-
Questions:
43+
* "Builds with ``exit_code=1``"
44+
* "Builds containing ``ERROR`` on their output"
45+
* "Projects created after X datetime"
46+
* "Versions with tag ``python``"
10147

102-
#. Do we want to add ``/api/v2/sustainability/`` to APIv3 or that
103-
should be part of the new Ad Server that we are building?
48+
* Cover *all the actions* available from the WebUI
10449

10550

106-
Proper status codes for error reporting
107-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
51+
Problems with APIv2
52+
-------------------
10853

109-
* Pros:
54+
There are several problem with our current APIv2 that we can list:
11055

111-
* user knows what it's happening and can take decisions about it
56+
* No authentication
57+
* It's read-only
58+
* Not designed for slugs
59+
* Useful APIs not exposed (only for internal usage currently)
60+
* Error reporting is a mess
61+
* Relationships between API resources is not obvious
62+
* Footer API endpoint returns HTML
11263

113-
* Cons:
11464

115-
* n/a
65+
Implementation stages
66+
---------------------
11667

68+
Version 1
69+
+++++++++
11770

118-
Relationship between API resources
119-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
71+
The first implementation of APIv3 will cover the following aspects:
12072

121-
* Pros:
73+
.. note::
12274

123-
* browse-able API by accessing to the default resource (Project)
124-
* knowing the project's slug you can perform all the actions related to it
75+
This is currently implemented and live. Although, it's only for internal testing.
12576

126-
* Cons:
77+
* Authentication
12778

128-
* more data is returned with all the links to the endpoints
79+
* all endpoints require authentication via ``Authorization:`` request header
80+
* detail endpoints are available for all authenticated users
81+
* only Project's maintainers can access listing endpoints
82+
* personalized listing
12983

84+
* Read and Write
13085

131-
Make footer API returns JSON
132-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
86+
* edit attributes from Version (only ``active`` and ``privacy_level``)
87+
* trigger Build for a specific Version
13388

134-
* Pros:
89+
* Accessible by slug
13590

136-
* users can build their own version menu flyout
137-
* cleaner than returning a HTML and injecting it
91+
* Projects are accessed by ``slug``
92+
* Versions are accessed by ``slug``
93+
* ``/projects/`` endpoint is the main one and all of the other are nested under it
94+
* Builds are accessed by ``id``, as exception to this rule
95+
* access all (active/non-active) Versions of a Project by ``slug``
96+
* get latest Build for a Project (and Version) by ``slug``
97+
* filter by relevant fields
13898

139-
* Cons:
99+
* Proper status codes to report errors
140100

141-
* we need to adapt our theme for this
101+
* Browse-able endpoints
142102

103+
* browse is allowed hitting ``/api/v3/projects/`` as starting point
104+
* ability to navigate clicking on other resources under ``_links`` attribute
143105

144-
Questions:
106+
* Rate limited
145107

146-
#. Do we want an specific endpoint for the footer?
147-
#. The flyout could be built by querying 2 or 3 of the regular
148-
endpoint. Would this add too much overhead to the page loading
149-
time?
150108

109+
Version 2
110+
+++++++++
151111

152-
Use cases
153-
---------
112+
Second iteration will polish issues found from the first step,
113+
and add new endpoints to allow *import a project and configure it*
114+
without the needed of using the WebUI as a main goal.
154115

155-
We want to cover
156-
++++++++++++++++
116+
After Version 2 is deployed,
117+
we will invite users that reach us as beta testers to receive more feedback
118+
and continue improving it by supporting more use cases.
157119

120+
This iteration will include:
158121

159-
* Return all **my** projects
160-
* Access all the resources by knowing the project's slug
161-
* Ability to filter by fields
122+
* Minor changes to fields returned in the objects
123+
* Import Project endpoint
124+
* Edit Project attributes ("Settings" and "Advanced settings-Global settings" in the WebUI)
125+
* Trigger Build for default version
126+
* Allow CRUD for Redirect, Environment Variables and Notifications (``WebHook`` and ``EmailHook``)
127+
* Documentation
162128

163-
* all the active versions of specific project
164129

165-
* Data about builds
130+
Version 3
131+
+++++++++
166132

167-
* latest build for project
168-
* latest build for a particular version of a project
169-
* status of a particular build
133+
Third iteration will implement granular permissions.
134+
Keeping in mind how Sphinx extension will use it:
170135

171-
* Perform write actions like
136+
* ``sphinx-version-warning`` needs to get *all active Versions of a Project*
137+
* An extension that creates a landing page, will need *all the subprojects of a Project*
172138

173-
* add a Domain,
174-
* add User as mantainer,
175-
* import a new Project under my username,
176-
* set the language of the Project,
177-
* trigger a Build,
178-
* activate/deactivate a Version to be built,
179-
* and all the actions you can perform from the Admin tab.
139+
To fulfill these requirements, this iteration will include:
180140

181-
* Retrieve all the information needed to create a custom version menu flyout
141+
* Scope-based authorization token
182142

183143

184-
Considering some useful cases for the corporate site:
144+
Version 4
145+
+++++++++
185146

186-
* Give access to a doc page (``objects.inv``, ``/design/core.html``)
147+
* Specific endpoint for our flyout menu (returning JSON instead of HTML)
187148

188149

189-
We do NOT want to cover
190-
+++++++++++++++++++++++
150+
Out of roadmap
151+
--------------
191152

192-
* Random filtering over a whole and not useful Resource
153+
These are some features that we may want to build at some point.
154+
Although, they are currently out of our near roadmap because they don't affect too many users,
155+
or are for internal usage only.
193156

194-
* "All the ``stable`` versions"
195-
* "Builds with ``exit_code`` equal to 257"
157+
* CRUD for Domain
158+
* Add User as maintainer
159+
* Give access to a documentation page (``objects.inv``, ``/design/core.html``)
160+
* Internal Build process
196161

197162

198-
Technical aspects that would be good to have
199-
--------------------------------------------
163+
Nice to have
164+
------------
200165

201-
* Rate limit
202166
* ``Request-ID`` header
203167
* `JSON minified by default`_ (maybe with ``?pretty=true``)
204168
* `JSON schema and validation`_ with docs_

0 commit comments

Comments
 (0)