Skip to content

Commit 4dc1aa0

Browse files
authored
Ship API v3 (#6169)
Ship API v3
2 parents 3634827 + 4c40669 commit 4dc1aa0

24 files changed

+259
-320
lines changed

docs/api/index.rst

+1
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ from Read the Docs.
1111
:maxdepth: 3
1212

1313
v2
14+
v3

docs/api/v2.rst

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
API v2
2-
======
1+
API v2 (deprecated)
2+
===================
33

44
The Read the Docs API uses :abbr:`REST (Representational State Transfer)`.
55
JSON is returned by all API responses including errors
66
and HTTP response status codes are to designate success and failure.
77

88
.. note::
99

10-
A newer API v3 is in early development stages.
10+
A newer and better API v3 is ready to use.
1111
Some improvements coming in v3 are:
1212

13-
* Search API
14-
* Write access
15-
* Simpler URLs which use slugs instead of numeric IDs
13+
* Simpler URLs which use slugs
14+
* Token based authentication
15+
* Import a new project
16+
* Activate a version
1617
* Improved error reporting
1718

18-
If there are features you would like in v3, please get in touch
19-
in the `issue tracker <https://github.com/readthedocs/readthedocs.org/issues>`_.
19+
See its full documentation at :doc:`/api/v3`.
2020

2121

2222
Authentication and authorization

docs/api/v3.rst

+69-109
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,10 @@
1-
:orphan:
2-
31
API v3
42
======
53

64
The Read the Docs API uses :abbr:`REST (Representational State Transfer)`.
75
JSON is returned by all API responses including errors
86
and HTTP response status codes are to designate success and failure.
97

10-
.. warning::
11-
12-
APIv3 is currently under development and it's not ready to use yet.
13-
14-
15-
.. note::
16-
17-
If you want to beta test it, please `get in touch`_ with us so we can give you early access.
18-
19-
.. _get in touch: mailto:[email protected]?subject=APIv3%20beta%20test
20-
218
.. contents:: Table of contents
229
:local:
2310
:backlinks: none
@@ -37,6 +24,11 @@ Token
3724
The ``Authorization`` HTTP header can be specified with ``Token <your-access-token>``
3825
to authenticate as a user and have the same permissions that the user itself.
3926

27+
.. note::
28+
29+
You will find your access Token under
30+
`your profile settings <https://readthedocs.org/accounts/tokens/>`_.
31+
4032

4133
Session
4234
~~~~~~~
@@ -55,6 +47,27 @@ When a user is trying to authenticate via session,
5547
Resources
5648
---------
5749

50+
This section shows all the resources that are currently available in APIv3.
51+
There are some URL attributes that applies to all of these resources:
52+
53+
:?fields=:
54+
55+
Specify which fields are going to be returned in the response.
56+
57+
:?omit=:
58+
59+
Specify which fields are going to be omitted from the response.
60+
61+
:?expand=:
62+
63+
Some resources allow to expand/add extra fields on their responses (see `Project details <#project-details>`__ for example).
64+
65+
66+
.. tip::
67+
68+
You can browse the full API by accessing its root URL: https://readthedocs.org/api/v3/
69+
70+
5871
Projects
5972
~~~~~~~~
6073

@@ -82,21 +95,8 @@ Projects list
8295
"results": ["PROJECT"]
8396
}
8497

85-
:>json integer count: total number of projects.
86-
:>json string next: URI for next set of projects.
87-
:>json string previous: URI for previous set of projects.
88-
:>json array results: array of ``project`` objects.
89-
90-
:query string name: name of the project.
91-
:query string name__contains: part of the name of the project.
92-
:query string slug: slug of the project.
93-
:query string slug__contains: part of the slug of the project.
9498
:query string language: language code as ``en``, ``es``, ``ru``, etc.
95-
:query string privacy_level: one of ``public``, ``private``, ``protected``.
9699
:query string programming_language: programming language code as ``py``, ``js``, etc.
97-
:query string repository_type: one of ``git``, ``hg``, ``bzr``, ``svn``.
98-
99-
:requestheader Authorization: token to authenticate.
100100

101101

102102
Project details
@@ -136,10 +136,6 @@ Project details
136136
},
137137
"default_version": "stable",
138138
"default_branch": "master",
139-
"privacy_level": {
140-
"code": "public",
141-
"name": "Public",
142-
},
143139
"subproject_of": null,
144140
"translation_of": null,
145141
"urls": {
@@ -174,23 +170,17 @@ Project details
174170
}
175171
}
176172

177-
:>json string name: The name of the project.
178-
:>json string slug: The project slug (used in the URL).
179-
180-
.. TODO: complete the returned data docs once agreed on this.
181-
182-
:requestheader Authorization: token to authenticate.
183-
184-
:statuscode 200: Success
185-
:statuscode 404: There is no ``Project`` with this slug
173+
:query string expand: allows to add/expand some extra fields in the response.
174+
Allowed values are ``active_versions``, ``active_versions.last_build`` and
175+
``active_versions.last_build.config``. Multiple fields can be passed separated by commas.
186176

187177

188178
Project create
189179
++++++++++++++
190180

191181
.. http:post:: /api/v3/projects/
192182
193-
Import a project into Read the Docs.
183+
Import a project under authenticated user.
194184

195185
**Example request**:
196186

@@ -219,13 +209,7 @@ Project create
219209

220210
**Example response**:
221211

222-
`See Project details <#project-details>`_
223-
224-
:requestheader Authorization: token to authenticate.
225-
226-
:statuscode 201: Created
227-
:statuscode 400: Some field is invalid
228-
212+
`See Project details <#project-details>`__
229213

230214
Project update
231215
++++++++++++++
@@ -292,17 +276,8 @@ Versions listing
292276
"results": ["VERSION"]
293277
}
294278

295-
:>json integer count: Total number of Projects.
296-
:>json string next: URI for next set of Projects.
297-
:>json string previous: URI for previous set of Projects.
298-
:>json array results: Array of ``Version`` objects.
299-
300-
:query integer limit: limit number of object returned
301-
:query integer offset: offset from the whole list returned
302-
:query boolean active: whether return active versions only
303-
:query boolean built: whether return only built version
304-
305-
:requestheader Authorization: token to authenticate.
279+
:query boolean active: return only active versions
280+
:query boolean built: return only built versions
306281

307282

308283
Version detail
@@ -366,19 +341,23 @@ Version update
366341

367342
**Example request**:
368343

344+
.. sourcecode:: bash
345+
346+
$ curl \
347+
-X PATCH \
348+
-H "Authorization: Token <token>" https://readthedocs.org/api/v3/projects/pip/version/0.23/ \
349+
-H "Content-Type: application/json" \
350+
-d @body.json
351+
352+
The content of ``body.json`` is like,
353+
369354
.. sourcecode:: json
370355

371356
{
372357
"active": true,
373-
"privacy_level": "public"
374358
}
375359

376-
:requestheader Authorization: token to authenticate.
377-
378360
:statuscode 204: Updated successfully
379-
:statuscode 400: Some field is invalid
380-
:statuscode 401: Not valid permissions
381-
:statuscode 404: There is no ``Version`` with this slug for this project
382361

383362

384363
Builds
@@ -468,22 +447,14 @@ Build details
468447
}
469448
}
470449

471-
:>json integer id: The ID of the build
472-
:>json string date: The ISO-8601 datetime of the build.
450+
:>json string created: The ISO-8601 datetime when the build was created.
451+
:>json string finished: The ISO-8601 datetime when the build has finished.
473452
:>json integer duration: The length of the build in seconds.
474453
:>json string state: The state of the build (one of ``triggered``, ``building``, ``installing``, ``cloning``, or ``finished``)
475-
:>json boolean success: Whether the build was successful
476454
:>json string error: An error message if the build was unsuccessful
477-
:>json string commit: A version control identifier for this build (eg. the commit hash)
478-
:>json string builder: The hostname server that built the docs
479-
:>json string cold_storage: Whether the build was removed from database and stored externally
480-
481-
:query boolean include_config: whether or not include the configs used for this build. Default is ``false``
482455

483-
:requestheader Authorization: token to authenticate.
484-
485-
:statuscode 200: Success
486-
:statuscode 404: There is no ``Build`` with this ID
456+
:query string expand: allows to add/expand some extra fields in the response.
457+
Allowed value is ``config``.
487458

488459

489460
Builds listing
@@ -511,9 +482,7 @@ Builds listing
511482
}
512483

513484
:query string commit: commit hash to filter the builds returned by commit
514-
:query boolean running: whether or not to filter the builds returned by currently building
515-
516-
:requestheader Authorization: token to authenticate.
485+
:query boolean running: filter the builds that are currently building/running
517486

518487

519488
Build triggering
@@ -534,13 +503,15 @@ Build triggering
534503

535504
**Example response**:
536505

537-
`See Build details <#build-details>`_
506+
.. sourcecode:: json
538507

539-
:requestheader Authorization: token to authenticate.
508+
{
509+
"build": "{BUILD}",
510+
"project": "{PROJECT}",
511+
"version": "{VERSION}"
512+
}
540513

541-
:statuscode 202: Accepted
542-
:statuscode 400: Some field is invalid
543-
:statuscode 401: Not valid permissions
514+
:statuscode 202: the build was triggered
544515

545516

546517
Subprojects
@@ -693,13 +664,6 @@ Translations listing
693664
"results": ["PROJECT"]
694665
}
695666

696-
:>json integer count: total number of projects.
697-
:>json string next: URI for next set of projects.
698-
:>json string previous: URI for previous set of projects.
699-
:>json array results: array of ``project`` objects.
700-
701-
:requestheader Authorization: token to authenticate.
702-
703667

704668
Redirects
705669
~~~~~~~~~
@@ -791,14 +755,21 @@ Redirect create
791755
"type": "page"
792756
}
793757

758+
.. note::
759+
760+
``type`` can be one of ``prefix``, ``page``, ``exact``, ``sphinx_html`` and ``sphinx_htmldir``.
761+
762+
Depending on the ``type`` of the redirect, some fields may not be needed:
763+
764+
* ``prefix`` type does not require ``to_url``.
765+
* ``page`` and ``exact`` types require ``from_url`` and ``to_url``.
766+
* ``sphinx_html`` and ``sphinx_htmldir`` types do not require ``from_url`` and ``to_url``.
767+
794768
**Example response**:
795769

796770
`See Redirect details <#redirect-details>`_
797771

798-
:requestheader Authorization: token to authenticate.
799-
800-
:statuscode 201: Created
801-
:statuscode 400: Some field is invalid
772+
:statuscode 201: redirect created successfully
802773

803774

804775
Redirect update
@@ -832,12 +803,6 @@ Redirect update
832803

833804
`See Redirect details <#redirect-details>`_
834805

835-
:requestheader Authorization: token to authenticate.
836-
837-
:statuscode 200: Success
838-
:statuscode 400: Some field is invalid
839-
840-
841806
Redirect delete
842807
++++++++++++++++
843808

@@ -853,9 +818,7 @@ Redirect delete
853818
-X DELETE \
854819
-H "Authorization: Token <token>" https://readthedocs.org/api/v3/projects/pip/redirects/1/
855820

856-
:requestheader Authorization: token to authenticate.
857-
858-
:statuscode 204: Deleted successfully
821+
:statuscode 204: Redirect deleted successfully
859822

860823

861824
Environment Variables
@@ -950,10 +913,7 @@ Environment Variable create
950913

951914
`See Environment Variable details <#environmentvariable-details>`_
952915

953-
:requestheader Authorization: token to authenticate.
954-
955-
:statuscode 201: Created
956-
:statuscode 400: Some field is invalid
916+
:statuscode 201: Environment variable created successfully
957917

958918

959919
Environment Variable delete
@@ -973,4 +933,4 @@ Environment Variable delete
973933

974934
:requestheader Authorization: token to authenticate.
975935

976-
:statuscode 204: Deleted successfully
936+
:statuscode 204: Environment variable deleted successfully

docs/development/design/apiv3.rst

+5-4
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,6 @@ Version 1
7070

7171
The first implementation of APIv3 will cover the following aspects:
7272

73-
.. note::
74-
75-
This is currently implemented and live. Although, it's only for internal testing.
76-
7773
* Authentication
7874

7975
* all endpoints require authentication via ``Authorization:`` request header
@@ -109,6 +105,10 @@ The first implementation of APIv3 will cover the following aspects:
109105
Version 2
110106
+++++++++
111107

108+
.. note::
109+
110+
This is currently implemented and live.
111+
112112
Second iteration will polish issues found from the first step,
113113
and add new endpoints to allow *import a project and configure it*
114114
without the needed of using the WebUI as a main goal.
@@ -124,6 +124,7 @@ This iteration will include:
124124
* Edit Project attributes ("Settings" and "Advanced settings-Global settings" in the WebUI)
125125
* Trigger Build for default version
126126
* Allow CRUD for Redirect, Environment Variables and Notifications (``WebHook`` and ``EmailHook``)
127+
* Create/Delete a Project as subproject of another Project
127128
* Documentation
128129

129130

0 commit comments

Comments
 (0)